Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int mod = 1e9 + 7;
  6.  
  7. int main() {
  8.     long long q, num;
  9.     cin >> num >> q;
  10.     long long res = num;
  11.     int offset = 0;
  12.     for (int i = 0; i < q; i++) {
  13.         char c;
  14.         cin >> c;
  15.         if (c == '+')
  16.         {
  17.             int d;
  18.             cin >> d;
  19.             if (num >= 1e11)
  20.             {
  21.                 res *= 10;
  22.                 res += d;
  23.                 res %= mod;
  24.                 offset++;
  25.             }
  26.             else
  27.             {
  28.                 num *= 10;
  29.                 num += d;
  30.                 res = num % mod;
  31.             }
  32.         }
  33.         else {
  34.             if (offset)
  35.             {
  36.                 res /= 10;
  37.                 res %= mod;
  38.                 offset--;
  39.             }
  40.             else
  41.             {
  42.                 num /= 10;
  43.                 res = num % mod;
  44.             }
  45.         }
  46.         cout << res << '\n';
  47.     }
  48.     //system("pause");
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement