18分?!

P1449 后缀表达式

HgSO4_QwQ @ 2021-07-21 14:50:31

#include<iostream>
#include<stack>
#include<queue>
using namespace std;

int a[10110110];

int Solve()
{
    char a;
    stack<int> s;
    while(cin>>a)
    {
        if(a=='.') continue;
        if(a=='@') 
        {
            break;
        }
        if(a>='0'&&a<='9') s.push(a-'0');
        else
        {
            int t2=s.top();
            s.pop();
            int t1=s.top();
            s.pop();
            if(a=='+') s.push(t1+t2);
            else if(a=='-') s.push(t1-t2);
            else if(a=='*') s.push(t1*t2);
            else if(a=='/') s.push(t1/t2);
        }       
    }  
    cout<<s.top();
}
int main()
{
    Solve();
    return 0;
}

by 清清老大 @ 2021-07-21 15:14:17

@Felder 你这样只能输入个位数


by HgSO4_QwQ @ 2021-07-21 15:40:17

谢谢,AC了


|