Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string formula;
- getline(cin, formula);
- reverse(formula.begin(), formula.end());
- stringstream ss;
- string formula_add_sub, L, op, R;
- ss << formula;
- ss >> L;
- while (ss >> op >> R) {
- if (op == "+" or op == "-") formula_add_sub += L + " " + op + " ", L = R;
- else if (op == "*") L = to_string( stoi(L) * stoi(R) );
- else if (op == "\\") L = to_string( stoi(L) / stoi(R) );
- }
- formula_add_sub += L;
- ss.clear();
- ss << formula_add_sub;
- ss >> L;
- while (ss >> op >> R) {
- if (op == "+") L = to_string( stoi(L) + stoi(R) );
- else if (op == "-") L = to_string( stoi(L) - stoi(R) );
- }
- cout << L << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement