WA求在此代码上小改(我只知道有几处错了)

P1449 后缀表达式

Cy_AlphaKai_CCF @ 2023-09-24 17:50:02

#include <bits/stdc++.h>
using namespace std;
int stack_[55], top;
int check(char s)
{
    if(s == '+')return 1;
    if(s == '-')return 2;
    if(s == '*')return 3;
    if(s == '/')return 4;
    return 0;
}
int trans(string num)
{
    int tmp=0,p=1;
    for (int i=num.size()-1;i>=0;i--)
    {
        tmp+=(num[i]-'0')*p;
        p*=10; 
    }
    return tmp;
}
int main(void)
{
    string str;
    cin>>str;
    int lst=0;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]=='@')
            break;
        if(str[i]>='0'&&str[i]<='9')
            continue;
        if(str[i]=='.')
        {
            string s=str.substr(lst+1); 
            int a;
            a=trans(s);
            stack_[++top]=a; 
            lst=i+1;
        }
        else
        {
            int b;
            b=check(str[i]);
            int x,y,z;
            y=stack_[top--];
            x=stack_[top--];
            if(b==1)z=y+x;
            if(b==2)z=x-y;
            if(b==3)z=x*y;
            if(b==4)z=x/y;
            stack_[++top]=z; 
            lst=i+1;
        }
    }
    cout<<stack_[top];
    return 0;
}

|