Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <math.h>
- #include <cmath>
- #include <algorithm>
- #include <stack>
- using std ::cin;
- using std ::cout;
- using std ::string;
- int perevod (char cc) {
- if (cc - '0' <= 9) {
- return cc - '0';
- } else {
- return cc - '0' - 39;
- }
- }
- long long podh (std ::string aa) {
- long long fir = 0;
- for (int ii = aa.size() - 1; ii >= 0; --ii) {
- fir += perevod(aa[ii]) * pow(16, aa.size() - 1 - ii);
- }
- return fir;
- }
- int main() {
- string ss;
- std ::cin >> ss;
- std ::stack<int> st;
- st.push(-1);
- for (int ii = 0; ii < ss.size(); ++ii) {
- if (ss[ii] != '*') {
- if (ss[ii] == '+') {
- st.push(-1);
- } else if (ss[ii] == '-') {
- st.push(-2);
- } else {
- st.push(perevod(ss[ii]));
- }
- } else {
- int cur = st.top();
- st.pop();
- ++ii;
- cur *=perevod(ss[ii]);
- st.push(cur);
- }
- }
- long long ans = 0;
- while (!st.empty()) {
- int cur = st.top();
- st.pop();
- int sign =st.top();
- st.pop();
- if (sign == -1) {
- ans +=cur;
- } else {
- ans -=cur;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement