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

注意字符数组作字符串用的时候要给'\0'保留空间

Posted by frkstyc at 2005-05-25 23:35:03 on Problem 2105
In Reply To:老是WA,不知道错哪了,自己手动测试没出错,难道数据会有特殊情况,请哪位朋友进来看看我的代码 Posted by:majia1 at 2005-05-25 23:28:22
> #include "stdio.h"
> 
> int main()
> {
> 	int cases;
> 	int i,j,k;
> 	int sum;
> 	int ip[4];
> 	char str[32];
> 	
> 	scanf("%d",&cases);
>     for(i=1;i<=cases;i++)
> 	{
> 		scanf("%s",str);
> 		for(j=0;j<4;j++)
>         {
> 			sum=0;
> 			for(k=j*8;k<(j+1)*8;k++)
> 			{
> 				sum=sum*2+str[k]-'0';
> 			}
>             ip[j]=sum;
> 		}
>         printf("%d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]);
> 	}
> 	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