Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- int top = 0, S[1000];
- int pop()
- {
- top--;
- return S[top + 1];
- }
- void push(int x)
- {
- S[++top] = x;
- }
- int main()
- {
- stack<int>st;
- char s[100];
- while(scanf("%s", s) != EOF)
- {
- if(s[0] == '+')
- {
- int a = pop();
- int b = pop();
- push(a + b);
- }
- else if(s[0] == '*')
- {
- int a = pop();
- int b = pop();
- push(a * b);
- }
- else if(s[0] == '-')
- {
- int a = pop();
- int b = pop();
- push(b - a);
- }
- else
- {
- push(atoi(s));
- }
- }
- printf("%d\n", S[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement