artemgf

Сверхдлинные суммы

Mar 18th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int a, b, c[1000001];
  7.  
  8. int main()
  9. {
  10.     int
  11.         long long n, x = 0;
  12.     cin >> n;
  13.     for (int i = 1; i <= n; i++)
  14.     {
  15.         cin >> a >> b;
  16.         c[i] = a + b;
  17.     }
  18.  
  19.     for (int i = n; i >= 1; i--)
  20.     {
  21.         if (c[i] + x < 10)
  22.         {
  23.             c[i] = c[i] + x;
  24.             x = 0;
  25.         }
  26.         else
  27.         {
  28.             c[i] = c[i]+x - 10;
  29.             x = 1;
  30.         }
  31.     }
  32.     if (x == 1) cout << 1;
  33.     for (int i = 1; i <= n; i++)
  34.         cout << c[i];
  35.  
  36.     _getch();
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment