| ||||||||||
| 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:我的为什么Wa啊,大牛在哪里,帮帮忙罗In Reply To:我的为什么Wa啊,大牛在哪里,帮帮忙罗 Posted by:inforyou at 2007-05-11 18:56:37 #include<iostream>
using namespace std;
int main(int argc, char* argv[])
{
int k,i,j,sum=0,n,b[8] = {128,64,32,16,8,4,2,1};
char a[9][32];
cin>>n;
for(k=0;k<n;k++)
cin>>a[k];
for(k=0;k<n;k++)
for(i =0,j=8; i < j; i++)
{
sum += b[i%8]*(a[k][i]-'0');
if(i == j-1)
{
if(j == 32)
{cout << sum << endl;
sum=0;
}
else
{
cout << sum <<"." ;
j +=8;
sum=0;
}
}
}
return 0;
}
我参考你的编写了上述代码,AC,你的错误有两点:
1.题目要求不是输入一行二进制值后便输出其IP ADRRESS,而是输入N行二进制后
,集体输出相应的IP ADRRESS.
2.当j==32后, 要使sum=0;当然以你错误的输出方式是不存在这个毛病的.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator