【Luogu1449】后缀表达式

problem

solution

codes

#include<iostream>
#include<stack>
using namespace std;
stack<int>s;
int main(){
    char ch; int t=0;
    while(cin>>ch && ch!='@'){
        if(ch>='0'&&ch<='9')t=t*10+ch-'0';
        else if(ch=='.'){
            s.push(t); t = 0;
        }else{
            int a = s.top(); s.pop();
            int b = s.top(); s.pop();
            if(ch=='+')s.push(b+a);
            else if(ch=='-')s.push(b-a);
            else if(ch=='*')s.push(b*a);
            else if(ch=='/')s.push(b/a);
        }
    }
    cout<<s.top()<<"
";
    return 0;
}
原文地址:https://www.cnblogs.com/gwj1314/p/9444666.html