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:我的为什么Wa啊,大牛在哪里,帮帮忙罗

Posted by whus200531130079 at 2007-06-28 20:09:07 on Problem 2105
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:
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