system error 为什么
#include<cstdio>#include<cstring>
using namespace std;
int *str2int(char *str)
{
int i ,len=strlen(str);
int *a=new int [(len+1)*sizeof(int)];
for(i=0;i<len;i++)
a[i]=(int)str[len-i-1]-48;
return a;
}
int check(int *a,int n)
{
int k=0,len=n;
while(a[len-1]==0&&len>1)
len--;
for(k=0;k<len;k++)
{
if(a[k]>=10)
{
a[k+1]=a[k+1]+a[k]/10;
a[k]=a[k]%10;
}
}
if(a[k]!=0)
len=k+1;
return len;
}
char *int2str(int *a,int n)
{
int i;
char *str=new char[(n+1)*sizeof(char)];
for(i=0;i<n;i++)
str[i]=(char)a[n-i-1]+48;
str[n]='\0';
return str;
}
char *addition(char *m1,char *m2)
{
int i,len1,len2;
int *t1,*t2;
len1=strlen(m1);
len2=strlen(m2);
int len=(len1>len2)?len1:len2;
t1=new int[(len+2)*sizeof(int)];
t2=new int[(len+2)*sizeof(int)];
t1=str2int(m1);
t2=str2int(m2);
for(i=len1;i<len+1;i++)
t1[i]=0;
for(i=len2;i<len+1;i++)
t2[i]=0;
for(i=0;i<len;i++)
t1[i]=t1[i]+t2[i];
len=check(t1,len);
return int2str(t1,len);
}
int main()
{
char s1[1010],s2[1010];
int n;
int m=0;
scanf("%d",&n);
while(n--)
{
scanf("%s%s",s1,s2);
printf("case %d:\n",++m);
printf("%s + %s = %s\n",s1,s2,addition(s1,s2));
}
return 0;
}
这是大数加法的一道acm题,
提交后为什么是system error
请教各位大神