fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. stack<int> st;
  4. int main() {
  5. string s;
  6. while(cin>>s){
  7. if (isdigit(s[0])){
  8. st.push(stoi(s));
  9. }
  10. else{
  11. int a,b;
  12. a=st.top();
  13. st.pop();
  14. b=st.top();
  15. st.pop();
  16. if (s=="+"){
  17. st.push(a+b);
  18. }
  19. else{
  20. if (s=="*"){
  21. st.push(a*b);
  22. }
  23.  
  24. else{
  25. if (s=="/"){
  26. st.push(a/b);
  27. }
  28. else{
  29.  
  30. st.push(a-b);
  31.  
  32. }
  33.  
  34. }
  35. }
  36. }
  37. }
  38. cout<<st.top();
  39. }
  40.  
Success #stdin #stdout 0.01s 5300KB
stdin
5 6 +
stdout
11