Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie(0);
  9.    
  10.     //cout << (int)'0';
  11.     vector<int> a;
  12.     string s, t, k;
  13.     int c, d, e;
  14.     getline(cin, s);
  15.     for (int i = 0; i < (int)s.size(); i++) {
  16.         if (s[i] == ' ')
  17.             continue;
  18.         if ((s[i] == '+') || (s[i] == '-') || (s[i] == '*')) {
  19.             c = a.back();
  20.             a.pop_back();
  21.             d = a.back();
  22.             a.pop_back();
  23.            
  24.             if (s[i] == '+')
  25.                 e = c + d;
  26.             if (s[i] == '-')
  27.                 e = d - c;
  28.             if (s[i] == '*')
  29.                 e = c * d;
  30.            
  31.            
  32.             a.push_back(e);
  33.         }
  34.         if ((s[i] >= '0') && (s[i] <= '9')) {
  35.             while (i < (int)s.size() && (s[i] >= '0') && (s[i] <= '9')) {
  36.                 t += s[i];
  37.                 ++i;
  38.             }
  39.             k = t;
  40.             a.push_back(stoi(k));
  41.             t = "";
  42.         }
  43.     }
  44.     cout << a[0];
  45. }
  46.  
  47. /*
  48. 8 9 + 1 7 - *
  49. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement