【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()<<"\n";
    return 0;
}
posted @ 2018-06-08 22:06  gwj1139177410  阅读(72)  评论(0编辑  收藏  举报
选择