Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. include <fstream>
  2. #include <stack>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. int main(){
  7. ifstream fin("postfix.in");
  8. ofstream fout("postfix.out");
  9. char symbol;
  10. stack<int> result;
  11. while(fin >> symbol){
  12. if (isdigit(symbol)){
  13. result.push(symbol - '0');
  14. continue;
  15. }
  16. int second = result.top();
  17. result.pop();
  18. int first = result.top();
  19. result.pop();
  20. if (symbol == '-')
  21. result.push(first - second);
  22. else if (symbol == '+')
  23. result.push(first + second);
  24. else if (symbol == '*')
  25. result.push(first * second);
  26. }
  27. fout << result.top();
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement