Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cctype>
- #include<string>
- using namespace std;
- int stack[100];
- int top=-1;
- void push(int ch) {
- top++;
- stack[top]=ch;
- }
- int pop () {
- int c = stack[top];
- top--;
- return c;
- }
- int result (int a,int b,char c) {
- int a1 = a;
- int b1 = b;
- switch(c) {
- case '+': return a1+b1;
- case '-': return a1-b1;
- case '*': return a1*b1;
- case '/': return a1/b1;
- case '%': return a1%b1;
- }
- }
- int main () {
- string s;
- cin >> s;
- for(int i=0;i<s.length();i++) {
- if(isdigit(s[i])) {
- push(s[i]-'0');
- }
- else {
- int a = pop();
- int b = pop();
- push(result(b,a,s[i]));
- }
- }
- cout << stack[top];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment