void reverse(char* num1, int n){
int head=0,tail=n-1;
while(head<=tail){
char c=num1[head];
num1[head]=num1[tail];
num1[tail]=c;
head++;
tail--;
}
}
int max(int i,int j){
if(i>j) return i;
return j;
}
char * addStrings(char * num1, char * num2){
int n1=strlen(num1),n2=strlen(num2);
char* temp=(char*)malloc(sizeof(char)*15000);
for(int i=0;i<15000;i++) temp[i]=0;
int pre=0,index=0;
reverse(num1,n1);
reverse(num2,n2);
int n=max(n1,n2);
while(index < n ){
int a=0,b=0;
if(index<n1) a=num1[index]-'0';
if(index<n2) b=num2[index]-'0';
temp[index++]=(a+b+pre)%10+'0';
pre=(a+b+pre)/10;
}
if(pre==1) temp[n]=1+'0';
reverse(temp,strlen(temp));
return temp;
}
标签:return,num1,num2,int,相加,char,415,字符串,strlen From: https://www.cnblogs.com/llllmz/p/18084468