AquaBlitz11

TASK_069 - AquaBlitz11's Solution

Mar 5th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. const int N = 10010;
  8. char a[N], b[N];
  9. char sum[N];
  10.  
  11. int main()
  12. {
  13.     scanf("%s %s", a, b);
  14.     reverse(a, a+strlen(a));
  15.     reverse(b, b+strlen(b));
  16.    
  17.     int i = 0, carry = 0;
  18.     while (a[i] || b[i] || carry) {
  19.         if (!a[i]) a[i] = '0';
  20.         if (!b[i]) b[i] = '0';
  21.         int v = carry + (a[i]-'0') + (b[i]-'0');
  22.         sum[i] = (v%10)+'0';
  23.         carry = v/10;
  24.         ++i;
  25.     }
  26.  
  27.     reverse(sum, sum+i);
  28.     printf("%s", sum);
  29.  
  30.     return 0;
  31. }
Add Comment
Please, Sign In to add comment