| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
[求助]1053怎么一直WA啊?如题,已经翻遍了discuss,里面所有的问题都注意到了。还是WA,不知道测试数据是什么样的,大牛么帮我看看把
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int min(int a,int b);
int main()
{
char result[110],num[110],final[110];
int nLen=0,rLen=0,carry=0,i,j=0,temp;
memset(result,0,sizeof(result));
result[0]='0';
memset(num,0,sizeof(num));
scanf("%s",num);
if(strcmp(num,"0")==0)
return 0;
while(strcmp(num,"0"))
{
nLen=strlen(num);
rLen=strlen(result);
strrev(num);
strrev(result);
for(i=0;i<min(nLen,rLen);i++)
{
temp=(int)(result[i]-'0')+(int)(num[i]-'0')+carry;
carry=temp/10;
result[i]=(char)(temp%10+'0');
}
if(rLen>=nLen)
while(i<rLen)
{
temp=(int)(result[i]-'0')+carry;
carry=temp/10;
result[i]=(char)(temp%10+'0');
i++;
}
else
while(i<nLen)
{
temp=(int)(num[i]-'0')+carry;
carry=temp/10;
result[i]=(char)(temp%10+'0');
i++;
}
if(carry==0)
result[i]='\0';
else
{
result[i]=(char)(carry+'0');
}
strrev(result);
scanf("%s",num);
}
for(i=0;result[i]=='0';i++);
while(result[i]!='\0'){
final[j++]=result[i++];
}
final[j]='\0';
if(strlen(final)==0)
printf("0\n");
else
printf("%s\n",final);
return 0;
}
int min(int a,int b)
{
return a>b?b:a;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator