求助 wa三组

P1449 后缀表达式

danefishhh @ 2019-02-16 09:15:43

莫名wa x是个用来算数的队列 q是计算的栈

#include<iostream>
#include<stack>
#include<cstring>
#include<queue>
using namespace std;
int t1,t2,cnt,tot;
string s;
stack <int > q;
queue <int > x;
int main() {
    cin>>s;
    int len=s.length();
    for(int i=0; i<len; i++) {
        if(s[i]=='@')
            break;
        if(s[i]<='9'&&s[i]>='0') {
            x.push(s[i]-'0');
            cnt++;
            continue;
        }
        if(s[i]=='.') {
            tot=0;
            while(cnt--) {
                if(cnt==0) {
                    tot+=x.front();
                    x.pop();
                } else {
                    tot+=x.front()*cnt*10;
                    x.pop();
                }
            }
            q.push(tot);
            cnt=0;
        } else if(s[i]!='.') {
            t1=q.top();
            q.pop();
            t2=q.top();
            q.pop();
            if(s[i]=='+') {
                q.push(t1+t2);
            }
            if(s[i]=='-') {
                q.push(t2-t1);
            }
            if(s[i]=='*') {
                q.push(t1*t2);
            }
            if(s[i]=='/') {
                q.push(t2/t1);
            }
        }
    }
    cout<<q.top();
    return 0;
}

|