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

Re:char ip[30];晕!有30位的IP吗?

Posted by ice_lemon at 2006-07-29 22:14:31 on Problem 2105
In Reply To:高手帮忙 为何WA? Posted by:Garra at 2006-04-07 22:26:21
> #include <iostream>
> using namespace std;
> 
> int n;
> char ip[30];
> int power_2[8]={1,2,4,8,16,32,64,128};
> int ip1,ip2,ip3,ip4;
> 
> int main()
> {
>     cin>>n;int j;
>     for(int i=0;i<n;i++)
>     {
>         cin>>ip;ip1=0;ip2=0;ip3=0;ip4=0;
>         for(j=0;j<=7;j++)
>         {
>             ip1+=(ip[j]-'0')*power_2[7-j];
>         }
>         for(j=8;j<=15;j++)
>         {
>             ip2+=(ip[j]-'0')*power_2[15-j];
>         }    
>         for(j=16;j<=23;j++)
>         {
>             ip3+=(ip[j]-'0')*power_2[23-j];
>         }    
>         for(j=24;j<=31;j++)
>         {
>             ip4+=(ip[j]-'0')*power_2[31-j];
>         }        
>         cout<<ip1<<'.'<<ip2<<'.'<<ip3<<'.'<<ip4<<endl;
>     }    
>     return 0;
> }    
> 
> 
> 
> 

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