zoj1205 高手帮我看的程序错在哪里

来源:百度知道 编辑:UC知道 时间:2024/06/04 05:11:26
ZOJ Problem Set - 1205Martian Addition

--------------------------------------------------------------------------------

Time Limit: 1 Second Memory Limit: 32768 KB

--------------------------------------------------------------------------------
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are very fond of mathematics. Every year, they would hold an Arithmetic Contest on Mars (ACM). The task of the contest is to calculate the sum of two 100-digit numbers, and the winner is the one who uses least time. This year they also invite people on Earth to join the contest.
As the only delegate of Earth, you're sent to Mars to demonstrate the power of mankind. Fortunately you have taken your laptop computer with you which can help you do the job quickly. Now the remaining problem is only to write a short program to calculate the sum of 2 given numbers. However, before you begin to program,

你没有处理 0 0输入的情况,输入0 0应该输出结果是0
修改代码可以AC
#include<stdio.h>
#include <string.h>
int main()
{
char s1[101],s2[101];
while(scanf("%s",s1)!=EOF&&scanf("%s",s2)!=EOF)
{
int a[101]={0},b[101]={0},c[102]={0},i=0,k=0,h=0;
memset(c,0,102);
while(s1[i]!='\0')
i++;
while(i>=1)
{
if(s1[i-1]>=48&&s1[i-1]<=57)
a[++k]=s1[--i]-48;
else
a[++k]=s1[--i]-87;
}

i=k=0;
while(s2[i]!='\0')
i++;
while(i>=1)
{
if(s2[i-1]>=48&&s2[i-1]<=57)
b[++k]=s2[--i]-48;
else
b[++k]=s2[--i]-87;
}
for(i=1;i<=100;i++)
{
c[i]=a[i]+b[i]+h;
h=c[i]/20;
c[i]=c[i]%20;
}

if(h)
{
c[i]=h;
}
i=101;

while(c[i]==0)