Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <math.h>
  5. #include <cmath>
  6. #include <algorithm>
  7. #include <stack>
  8. using std ::cin;
  9. using std ::cout;
  10. using std ::string;
  11. int perevod (char cc) {
  12.     if (cc - '0' <= 9) {
  13.        return cc - '0';
  14.     } else {
  15.         return cc - '0' - 39;
  16.     }
  17. }
  18.  
  19. long long podh (std ::string aa) {
  20.     long long fir = 0;
  21.     for (int ii = aa.size() - 1; ii >= 0; --ii) {
  22.         fir += perevod(aa[ii]) * pow(16, aa.size() - 1 - ii);
  23.     }
  24.     return fir;
  25. }
  26.  
  27. int main() {
  28.     string ss;
  29.     std ::cin >> ss;
  30.     std ::stack<int> st;
  31.     st.push(-1);
  32.     for (int ii = 0; ii < ss.size(); ++ii) {
  33.         if (ss[ii] != '*') {
  34.             if (ss[ii] == '+') {
  35.                 st.push(-1);
  36.             } else if (ss[ii] == '-') {
  37.                 st.push(-2);
  38.             } else {
  39.                 st.push(perevod(ss[ii]));
  40.             }
  41.         } else {
  42.             int cur = st.top();
  43.             st.pop();
  44.             ++ii;
  45.             cur *=perevod(ss[ii]);
  46.             st.push(cur);
  47.         }
  48.     }
  49.     long long ans = 0;
  50.     while (!st.empty()) {
  51.         int cur = st.top();
  52.         st.pop();
  53.         int sign =st.top();
  54.         st.pop();
  55.         if (sign == -1) {
  56.             ans +=cur;
  57.         } else {
  58.             ans -=cur;
  59.         }
  60.     }
  61.     cout << ans;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement