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 happy__ting at 2010-05-27 19:21:53 on Problem 2845
In Reply To:各种数据都过了。WA。求解释。 Posted by:happy__ting at 2010-05-27 19:17:50
#include<stdio.h>
#include<string.h>
char a[1005];
char b[1005];
char c[1005];
int main()
{
	int i,n,len1,len2,j,max,min,t;
	char ch;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{   
		t=0;
		scanf("%s %s",a,b);
		len1=strlen(a);
		len2=strlen(b);
		for(j=0;j<len1/2;j++)
		{
			ch=a[j];
			a[j]=a[len1-j-1];
			a[len1-j-1]=ch;
		}
		for(j=0;j<len2/2;j++)
		{
			ch=b[j];
			b[j]=b[len2-j-1];
			b[len2-j-1]=ch;
		}
		max=len1>len2?len1:len2;
		min=len1+len2-max;
		for(j=0;j<min;j++)
		{
			t=t+a[j]+b[j]-'0'-'0';
			c[j]=t%2+'0';
			t/=2;
		}
		for(j=min;j<max;j++)
		{
			t=t+a[j]+b[j]-'0';
			c[j]=t%2+'0';
			t/=2;
		}
		if(t==1)
			c[max]='1';
		else
			c[max]='0';
		printf("%d ",i+1);
		for(j=max;j>=1;j--)
			if(c[j]!='0')
			{
				printf("%c",c[j]);
				--j;
				break;
			}
		for(;j>=1;j--)
			printf("%c",c[j]);
		printf("%c",c[0]);
		printf("\n");
	}
	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