1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
#include <cstdlib> #include <iostream> #include <stack> #include <cstring> using namespace std; int polish(char* oper) { int i, o1, o2; stack<int> a; for (i=0; i<strlen(oper); i++) { if (int(oper[i])>47 && int(oper[i])<58) { a.push(oper[i]-'0'); } switch (oper[i]) { case '+': o1=a.top(); a.pop(); o2=a.top(); a.pop(); a.push(o1+o2); break; case '-': o1=a.top(); a.pop(); o2=a.top(); a.pop(); a.push(o1-o2); break; case '*': o1=a.top(); a.pop(); o2=a.top(); a.pop(); a.push(o1*o2); break; case '/': o1=a.top(); a.pop(); o2=a.top(); a.pop(); a.push(o1/o2); break; } } return a.top(); } int main() { char* oper; cin>>oper; cout<<polish(oper); system("pause"); }