题目链接:me
我的WA代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
stack<int>q;
int x;
string s;
signed main() {
getline(cin,s);
for(int i=0;i<s.size()-1;i++) {
char ch=s[i];
if(ch!=' ') {
if(isdigit(ch)) {
int x=0;
while(s[i]!=' ') {
x=x*10+s[i]-'0';
i++;
}
q.push(x);
}
else {
int top1=q.top();
q.pop();
int top2=q.top();
q.pop();
if(ch=='+') q.push(top2+top1);
else if(ch=='-') q.push(top2-top1);
else if(ch=='*') q.push(top2*top1);
else q.push(top2/top1);
}
}
}
cout<<q.top();
return 0;
}
哪位大佬帮个忙,我一直错。