The "A+B problem" is very easy,but I failed for many times.
The code:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #define LL long long14 #define MAXN 5000115 #define P 12345616 using namespace std;17 int a[P],b[P],c[P],ka=1,kb=1;18 char ca[P],cb[P];19 int main()20 {21 scanf("%s%s",ca,cb);22 int lena=strlen(ca),lenb=strlen(cb);23 int j=1;24 for(int i=lena-1;i>=0;i--)25 {26 a[ka]+=j*(ca[i]-'0');27 j*=10;28 if(j==1000)29 j=1,ka++;30 }31 32 if(j!=1)33 ka++,j=1;34 for(int i=lenb-1;i>=0;i--)35 {36 b[kb]+=j*(cb[i]-'0');37 j*=10;38 if(j==1000)39 j=1,kb++;40 }41 if(j!=1)42 kb++,j=1;43 44 //a[],b[] finish45 46 int e=0;47 for(int i=1;i<=max(ka,kb);i++)48 {49 c[i]=(a[i]+b[i]+e)%1000;50 e=(a[i]+b[i]+e)/1000;51 }52 int k=max(ka,kb)+1;53 while(k>0&&!c[k]) k--;54 printf("%d",c[k]);55 for(int i=k-1;i>=1;i--)56 printf("%03d",c[i]);57 58 return 0;59 }
I have forgot to plus the "e" first, so I have so much mistake!!!