Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <fstream>
- #include <stack>
- #include <cctype>
- using namespace std;
- int main(){
- ifstream fin("postfix.in");
- ofstream fout("postfix.out");
- char symbol;
- stack<int> result;
- while(fin >> symbol){
- if (isdigit(symbol)){
- result.push(symbol - '0');
- continue;
- }
- int second = result.top();
- result.pop();
- int first = result.top();
- result.pop();
- if (symbol == '-')
- result.push(first - second);
- else if (symbol == '+')
- result.push(first + second);
- else if (symbol == '*')
- result.push(first * second);
- }
- fout << result.top();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement