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

诚心请教,为什么过不了?当前的提示中的数据都过了

Posted by 330332 at 2007-11-02 23:55:49 on Problem 2845
#include <stdio.h>
#include <memory.h>
#include <cstring>
int main()
{
	int n,m=1;
	scanf("%d",&n);
	char a[1001],b[1001];
	int c[1001];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	while( m<=n )
	{
		int i=0,j=0,alen=0,blen=0;
		while( scanf("%s%s",&a,&b)==2 )
		{
		alen=strlen(a);
		blen=strlen(b);
		int clen=0,carry=0;

		int d=(int)b[0];
		int p=0,q=0;
		
		while( alen>0 && blen>0 )
		{
			p=(int)a[alen-1];
			q=(int)b[blen-1];
			p-=48;
			q-=48;
			c[clen]=carry + p + q ;
			if( c[clen]>=2 )
			{
				carry=1;
			}
			else
			{
				carry=0;
			}
			
			if( c[clen]>=2 )
			{
				c[clen]-=2;
			}
			alen--;
			blen--;
			clen++;
		}
		
		if( alen>0 )
		{
			while( alen>0 )
			{
				p=(int)a[alen-1];
				p-=48;
				c[clen]=p+carry;
				if( c[clen]>=2 )
				{
					c[clen]-=2;
					carry=1;
				}
				else
				{
					carry=0;
				}
				clen++;
				alen--;
			}
		}

		if( blen>0 )
		{
			while( blen>0 )
			{
				q=(int)b[blen-1];
				q-=48;
				c[clen]=q+carry;
				if( c[clen]>=2 )
				{
					c[clen]-=2;
					carry=1;
				}
				else
				{
					carry=0;
				}
				clen++;
				blen--;
			}
		}

		if( alen<=0 && blen<=0 )
		{
			if( carry==1 )
			{
				c[clen]=1;
			}
		}
		
		printf("%d ",m);
		while( c[clen]==0 && clen>0 )
		{
			clen--;
		}
		for( int k=clen;k>=0;k-- )
		{
			printf("%d",c[k]);
		}
		printf("\n");
		m++;
		}
		
	}
	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