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

请教高手,为什么还wa,还有没有测试数据啊

Posted by xiao1074234390 at 2012-07-25 18:07:38 on Problem 1504
#include<stdio.h>
#include<string.h>
void del(char a[100])/*去前导和后导0*/
{
	int i=0,j=0,len;
	len=strlen(a)-1;
	while(a[i]=='0')
		i++;
	for(j=len;;j--)
	{
		if(a[j]=='0')
			len--;
		else
			break;
	}
	a[len+1]='\0';
	j=0;
	while(a[i])
	{
		a[j]=a[i];
		i++;
		j++;
	}
	a[j]='\0';
	
}
int s(char a[100],char b[100],int m)/*求和*/
{
	int i,t,c=0,len;
	len=strlen(b);
	for(i=0;b[i];i++)
	{
		t=a[i]+b[i]-'0'-'0'+c;
		if(t>9)
		{
			t=t-10;
			c=1;
		}
		else
			c=0;
		a[i]=t+'0';
	}
	if(m==len)
	{
		if(c==1)
		{
		    a[i]='1';
		    a[i+1]='\0';
		}
	    else
		    a[i]='\0';
		return 0;

	}
	for(;a[i];i++)
	{
		t=a[i]-'0'+c;
		if(t>9)
		{
			t=t-10;
			c=1;
		}
		else
			c=0;
		a[i]=t+'0';
	}
	if(c==1)
	{
		a[i]='1';
		a[i+1]='\0';
	}
	else
		a[i]='\0';
	return 0;
}
void main()
{
	char N,a[100],b[100];
	int m,n,t;
	int i=0;
	scanf("%d",&N);
	while(N--)
	{
		scanf("%s %s",&a,&b);
		del(a);
		del(b);
	    m=strlen(a);
	    n=strlen(b);
	    if(m>=n)
		{
			s(a,b,m);
			del(a);
			printf("%s\n",a);
		}
    	else
		{
		    s(b,a,n);
			del(b);
			printf("%s\n",b);
		}
	}
}

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