Постфиксная запись
unknown
c_cpp
a year ago
877 B
9
Indexable
#include <bits/stdc++.h> //karuseel using namespace std; int main() { string s; stack<int> st; while (cin >> s) { if (s != "+" && s != "-" && s != "*") { st.push(stoi(s)); } else { if (s == "+") { int vp = st.top(); st.pop(); vp = vp + st.top(); st.pop(); st.push(vp); } else if (s == "-") { int vp = st.top(); st.pop(); vp = st.top() - vp; st.pop(); st.push(vp); } else if (s == "*") { int vp = st.top(); st.pop(); vp = vp * st.top(); st.pop(); st.push(vp); } } } cout << st.top(); return 0; }
Editor is loading...
Leave a Comment