Untitled
user_1737235546
plain_text
2 years ago
1.5 kB
4
Indexable
Never
#include <stdio.h> #include <string.h> int max(int a,int b){ if(a>b) return a; else return b; } int main(){ char a[200], b[200], c[200], d[200]; scanf("%s%s",a,b); int ad=strlen(a), bd=strlen(b); if(ad>bd){ for(int i=0; i<ad-bd; i++){ d[i]='0'; c[i]=a[i]; } for(int i=ad-bd; i<ad; i++){ d[i]=b[i-ad+bd]; c[i]=a[i]; } } else{ for(int i=0; i<bd-ad; i++){ c[i]='0'; d[i]=b[i]; } for(int i=bd-ad; i<bd; i++){ c[i]=a[i+ad-bd]; d[i]=b[i]; } } char ans[max(ad,bd)+5]; int tmp=0,tmp2=0; for(int i=max(ad,bd)-1; i>=0; i--){ if(c[i]==',' || d[i]==','){ ans[i]=','; continue; } if(tmp==1){ ans[i]='1'; tmp=0; } else{ ans[i]='0'; } //printf("c=%c,d=%c,c+d=%d\n",c[i],d[i],(c[i]+d[i]-'0'-'0')%10); if(i!=0 && (ans[i]+c[i]+d[i]-'0'-'0'-'0')>=10){ tmp=1; } else if(i==0 && (ans[i]+c[i]+d[i]-'0'-'0'-'0')>=10){ tmp2=1; } ans[i]=ans[i]+(c[i]+d[i]-'0'-'0')%10; if(ans[i]>'9') ans[i]=ans[i]-10; } if(tmp2==1 && strlen(ans)%4==3) printf("1,"); else if(tmp2==1 && strlen(ans)%4!=3) printf("1"); for(int i=0; i<max(ad,bd); i++){ printf("%c",ans[i]); } printf("\n"); return 0; }