Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- //cout << (int)'0';
- vector<int> a;
- string s, t, k;
- int c, d, e;
- getline(cin, s);
- for (int i = 0; i < (int)s.size(); i++) {
- if (s[i] == ' ')
- continue;
- if ((s[i] == '+') || (s[i] == '-') || (s[i] == '*')) {
- c = a.back();
- a.pop_back();
- d = a.back();
- a.pop_back();
- if (s[i] == '+')
- e = c + d;
- if (s[i] == '-')
- e = d - c;
- if (s[i] == '*')
- e = c * d;
- a.push_back(e);
- }
- if ((s[i] >= '0') && (s[i] <= '9')) {
- while (i < (int)s.size() && (s[i] >= '0') && (s[i] <= '9')) {
- t += s[i];
- ++i;
- }
- k = t;
- a.push_back(stoi(k));
- t = "";
- }
- }
- cout << a[0];
- }
- /*
- 8 9 + 1 7 - *
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement