文章
36
粉丝
0
获赞
5
访问
24.3k
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
int main(){
char s1[1000],s2[1000],r[2000];
while(scanf("%s %s",s1,s2)!=EOF){
int len = strlen(s1);
int temp=0,count=0,plus=0;
for(int i=len-1;i>=0;i--){
if(i==0&&((s1[i]-'0')+(s2[i]-'0')>=10)){
temp = (s1[i]-'0')+(s2[i]-'0');
r[count++] = temp%10+plus+'0';
plus = temp / 10; //15+15
r[count++] = plus+'0';
}
else{
temp = (s1[i]-'0')+(s2[i]-'0');
r[count++] = temp%10+plus+'0';
plus = temp / 10; //15+15
}
}
for(int i=count-1;i>=0;i--) printf("%c",r[i]);
printf("\n");
}
return 0;
}
登录后发布评论
plus的位置加错了
temp = (s1[i]-'0')+(s2[i]-'0')+plus;