Advertisement
Adrita

task 4( ds lab 4) 3rd sem

Jan 30th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,i;
  6. cin>>t;
  7. stack <int> s;
  8. while(t--)
  9. {
  10. string a;
  11. cin>>a;
  12. for(i=0; i<a.size(); i++)
  13. {
  14. if(isdigit(a[i]))
  15. s.push(a[i]-'0');
  16. else
  17. {
  18. int v1=s.top();
  19. s.pop();
  20. int v2=s.top();
  21. s.pop();
  22. if(a[i]=='+')
  23. s.push(v2+v1);
  24. else if(a[i]=='-')
  25. s.push(v2-v1);
  26. else if(a[i]=='*')
  27. s.push(v2*v1);
  28. else if(a[i]=='/')
  29. s.push(v2/v1);
  30. }
  31. }
  32. cout<<s.top()<<endl;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement