Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:char ip[30];晕!有30位的IP吗?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator