Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- #include <string>
- using namespace std;
- stack<int> st;
- int main()
- {
- string s;
- int i,j,b,c;
- getline(cin,s);
- for(i=0;i<s.size();++i)
- {
- if(s[i]>='0' && s[i]<='9')
- st.push(s[i]-'0');
- else
- {
- if(s[i]=='+')
- {
- b=st.top();
- st.pop();
- c=st.top();
- st.pop();
- st.push(b+c);
- }
- if(s[i]=='-')
- {
- b=st.top();
- st.pop();
- c=st.top();
- st.pop();
- st.push(c-b);
- }
- if(s[i]=='*')
- {
- b=st.top();
- st.pop();
- c=st.top();
- st.pop();
- st.push(b*c);
- }
- }
- }
- cout<<st.top();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment