求助!

P1449 后缀表达式

xxxzh28 @ 2021-10-05 14:49:36


#include<bits/stdc++.h>
using namespace std;
string s;
int z,t,c=0,sta[10001000],a1,a2;
int sb(int x,int y){
    if(s[c]=='+')
    return x+y;
    if(s[c]=='-')
    return y-x;
    if(s[c]=='*')
    return x*y;
    if(s[c]=='/')
    return x/y;
}
int main(){
    getline(cin,s);
    while(s[c]!='@'){
        if(s[c]>='0'&&s[c]<='9')
            z=z*10+s[c]-'0';
            else
            {
            if(z!=0){
                sta[t++]=z;

                z=0;
            }
            else if(s[c]=='+'||s[c]=='-'||s[c]=='*'||s[c]=='/'){
                a2=sta[t];
                t-=1;
                a1=sta[t];
                sta[t]=sb(a1,a2);

            }

          }
          c+=1;
        }

    cout<<sta[t];
    return 0;
}

|