Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- #include <vector>
- #include <stack>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e5 + 10;
- const int N = 2e5;
- int make_op(int a, int b, char op) {
- if (op == '+') {
- return a + b;
- }
- if (op == '-') {
- return a - b;
- }
- if (op == '*') {
- return a * b;
- }
- }
- int convert(string& s) {
- int ans = 0;
- for (auto& i: s) {
- ans *= 10;
- ans += (int)(i - '0');
- }
- return ans;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- stack<int> st;
- string s;
- while (cin >> s) {
- if (s[0] >= '0' && s[0] <= '9') {
- st.push(convert(s));
- } else {
- int a = st.top();
- st.pop();
- int b = st.top();
- st.pop();
- swap(a, b);
- st.push(make_op(a, b, s[0]));
- }
- }
- cout << st.top() << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment