#include <iostream>
#include <stdio.h>
#include <memory.h>
using namespace std;
char tab[5120],tab2[5120],tab3[5120];
int main() {
// your code goes here
scanf("%s\n%s",tab,tab2);
int k=strlen(tab)-1;
int k2=strlen(tab2)-1;
int p=0;
int i=5060;
//printf("%d %d %c %c %d\n",k, k2, tab[k], tab2[k2], p);
while(k>=0 && k2>=0 || p)
{
int a = k>=0&&tab[k]?tab[k]-'0':0;
int b = k2>=0&&tab2[k2]?tab2[k2]-'0':0;
a+=b+p;
tab3[i] = (a%10)+'0';
p=a/10;
k--;
k2--;
i--;
//printf("%d\n",a);
}
printf("%s",tab3+i+1);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> #include <stdio.h> #include <memory.h> using namespace std; char tab[5120],tab2[5120],tab3[5120]; int main() { // your code goes here scanf("%s\n%s",tab,tab2); int k=strlen(tab)-1; int k2=strlen(tab2)-1; int p=0; int i=5060; //printf("%d %d %c %c %d\n",k, k2, tab[k], tab2[k2], p); while(k>=0 && k2>=0 || p) { int a = k>=0&&tab[k]?tab[k]-'0':0; int b = k2>=0&&tab2[k2]?tab2[k2]-'0':0; a+=b+p; tab3[i] = (a%10)+'0'; p=a/10; k--; k2--; i--; //printf("%d\n",a); } printf("%s",tab3+i+1); return 0; } |
English