Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t,i;
- cin>>t;
- stack <int> s;
- while(t--)
- {
- string a;
- cin>>a;
- for(i=0; i<a.size(); i++)
- {
- if(isdigit(a[i]))
- s.push(a[i]-'0');
- else
- {
- int v1=s.top();
- s.pop();
- int v2=s.top();
- s.pop();
- if(a[i]=='+')
- s.push(v2+v1);
- else if(a[i]=='-')
- s.push(v2-v1);
- else if(a[i]=='*')
- s.push(v2*v1);
- else if(a[i]=='/')
- s.push(v2/v1);
- }
- }
- cout<<s.top()<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement