杭电acm1002高精度算法,新人求助
#include <iostream>#include <string.h>
#include <stdio.h>
using namespace std;
int main()
{
char a[1005],b[1005];
int y=0,q;
scanf("%d",&q);
while(q--)
{ scanf("%s %s",a,b);
char m[1006];
int c[1005]={0},d[1005]={0};
int e=0,f=0,i=0,k=0,v,mx,len1,len2,w,x=0;
len1=strlen(a);
len2=strlen(b);
if(len1>len2){mx=len1;}else{mx=len2;}
for(i=len1-1;i>=0;i--)
{
c[e]=a[i]-'0';
e++;
}
for(i=len2-1;i>=0;i--)
{
d[f]=b[i]-'0';
f++;
}
v=0;
w=mx;
while(w--)
{
c[k]=c[k]+d[k]+v;
if(c[k]>9)
{
c[k]=c[k]-10;
v=1;
}else{v=0;}
k++;
}
if(v==1)
{
c[mx]=1;
mx++;
}
e=0;
while(mx--)
{
m[e]=c[mx]+48;
e++;
}
y++;
printf("Case %d:\n",y);
printf("%s + %s = %s\n",a,b,m);
if(q>0){printf("\n");}
e=0,f=0,i=0,k=0;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));memset(c,0,sizeof(c));memset(d,0,sizeof(d));memset(m,0,sizeof(m));
}
return 0;
}
自己输出时格式是对的但是用c++判是Presentation Error,用g++是WA
求助高手