Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

朴素算法过 题目真水

Posted by shenyi0828 at 2009-03-04 11:05:00 on Problem 2105
#include <iostream>
using namespace std;

char twoBitNum[32];
int map[8]={128,64,32,16,8,4,2,1};
int IPAdr[4];

void input();
void standerlize();
void output();
void clear();

int main()
{
    int n;
    cin>>n;
    cin.ignore(33,'\n');
    for (int i=0;i<n;i++) {
        clear();
        input();
        standerlize();
        output();
    }
    return 0;
}

void input() {
     for (int j=0;j<32;j++) {
         cin>>twoBitNum[j];
     }
}

void clear() {
     for (int j=0;j<4;j++) {
         IPAdr[j]=0;
     }
}

void output() {
     for (int j=0;j<3;j++) {
         cout<<IPAdr[j]<<'.'<<flush;
     }
     cout<<IPAdr[3]<<endl;
}

void standerlize () {
     for (int j=0;j<4;j++) {
         for (int k=0;k<8;k++) {
             if (twoBitNum[j*8+k]=='1') IPAdr[j]+=map[k];
         }
     }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator