Created
June 23, 2014 09:26
-
-
Save yuji314159/54360992425a99049a88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
#include <stack> | |
using namespace std; | |
int main() | |
{ | |
stack<int> s; | |
char token[256]; | |
int a, b; | |
while (cin >> token) { | |
switch (token[0]) { | |
case '+': | |
b = s.top(); s.pop(); | |
a = s.top(); s.pop(); | |
s.push(a + b); | |
break; | |
case '-': | |
b = s.top(); s.pop(); | |
a = s.top(); s.pop(); | |
s.push(a - b); | |
break; | |
case '*': | |
b = s.top(); s.pop(); | |
a = s.top(); s.pop(); | |
s.push(a * b); | |
break; | |
case '/': | |
b = s.top(); s.pop(); | |
a = s.top(); s.pop(); | |
s.push(a / b); | |
break; | |
default: | |
s.push(atoi(token)); | |
break; | |
} | |
} | |
cout << s.top() << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment