P1449 后缀表达式

点击查看代码
#include<bits/stdc++.h>
using namespace std;

stack<int> stk;


int main()
{
    char c;
    int num=0;
    
    while(cin>>c){
        if(c=='@') break;

        if(c>='0'&&c<='9'){
            num=num*10+(c-'0');
        }

        else if(c=='.'){
            stk.push(num);
            num=0;
        }
        else {
            int y=stk.top();stk.pop();
            int x=stk.top();stk.pop();
            if(c=='+') stk.push(x+y);
            else if(c=='-') stk.push(x-y);
            else if(c=='*') stk.push(x*y);
            else if(c=='/') stk.push(x/y);
               
        }
    }

    cout<<stk.top()<<endl;

    return 0;
}
posted @ 2026-02-04 23:03  AnoSky  阅读(6)  评论(0)    收藏  举报