3493 WA

Do you want to discuss about these problems? Go now!
Users are shared (no need to re-register).

Moderator: Board moderators

Post Reply
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

3493 WA

Post by Obaida » Thu Jan 15, 2009 9:30 am

I have WA for this problem. Some one plz help.

Code: Select all

#include<stdio.h>
#include<string.h>

int main()
{
	bool carry;
	char num1[82],num2[82],res[82];
	int n,i,len1,len2,max,c=0,a,b,l;
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		c++;
		scanf("%s %s",&num1,&num2);
		carry=0;
		len1 = strlen(num1);
		len2 = strlen(num2);
		if(len1>len2)max = len1;
		else max = len2;
		for(i=0;i<len1;i++)
		{
			if(num1[i]!='0')
			{
				a = i;break;
			}
		}
		for(i=0;i<len2;i++)
		{
			if(num2[i]!='0')
			{
				b = i;break;
			}
		}
		len1--;len2--;max--;
		for(i=0;i<=max;i++)
		{
			if(len1-i<a&&len2-i<b)break;
			else if(len2-i<b)
			{
				if(num1[len1-i]=='1'&&carry)
				{
					res[max-i] = '0';
					carry = 1;
				}
				else if((num1[len1-i]=='0'&&carry)||(num1[len1-i]=='1'&&!carry))
				{
					res[max-i] = '1';
					carry = 0;
				}
				else
				{
					res[max-i] = '0';
					carry = 0;
				}
			}
			else if(len1-i<a)
			{
				if(num2[len2-i]=='1'&&carry)
				{
					res[max-i] = '0';
					carry = 1;
				}
				else if((num2[len2-i]=='0'&&carry)||(num2[len2-i]=='1'&&!carry))
				{
					res[max-i] = '1';
					carry = 0;
				}
				else
				{
					res[max-i] = '1';
					carry = 0;
				}
			}
			else
			{
				if(num1[len1-i]=='1'&&num2[len2-i]=='1'&&carry)
				{
					res[max-i]='1';
					carry = 1;
				}
				else if(num1[len1-i]=='1'&&num2[len2-i]=='1'&&!carry)
				{
					res[max-i] = '0';
					carry = 1;
				}
				else if(((num1[len1-i]=='1'&&num2[len2-i]=='0')||(num1[len1-i]=='0'&&num2[len2-i]=='1'))&&carry)
				{
					res[max-i] = '0';
					carry = 1;
				}
				else if(((num1[len1-i]=='1'&&num2[len2-i]=='0')||(num1[len1-i]=='0'&&num2[len2-i]=='1'))&&!carry)
				{
					res[max-i] = '1';
					carry = 0;
				}
				else if(num1[len1-i]=='0'&&num2[len2-i]=='0'&&carry)
				{
					res[max-i] = '1';
					carry = 0;
				}
				else
				{
					res[max-i] = '0';
					carry = 0;
				}
			}
		}
		if(a<b)l = a;
		else l = b;
		printf("%d ",c);
		if(carry)printf("1");
		for(i=l;i<=max;i++)
			printf("%c",res[i]);
		puts("");
	}
	return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.

Post Reply

Return to “ACM ICPC Archive Board”