Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- const int N = 10010;
- char a[N], b[N];
- char sum[N];
- int main()
- {
- scanf("%s %s", a, b);
- reverse(a, a+strlen(a));
- reverse(b, b+strlen(b));
- int i = 0, carry = 0;
- while (a[i] || b[i] || carry) {
- if (!a[i]) a[i] = '0';
- if (!b[i]) b[i] = '0';
- int v = carry + (a[i]-'0') + (b[i]-'0');
- sum[i] = (v%10)+'0';
- carry = v/10;
- ++i;
- }
- reverse(sum, sum+i);
- printf("%s", sum);
- return 0;
- }
Add Comment
Please, Sign In to add comment