我的做法是数组模拟栈,0分,求调试,不要代码谢谢 Thanks♪(・ω・)ノ
样例能过QWQ
#include<bits/stdc++.h>
using namespace std;
long long t[260];
string s;
long long TWT(string s)
{
long long i=0,top=0,x=0;
while(i<s.size()-1)
{
if(s[i]<='9'&&s[i]>='0') x=x*10+int(s[i]-'0');
else{
if(s[i]==' '&&s[i-1]>='0'&&s[i-1]<='9'){
top++;
t[top]=x;
x=0;
}
else{
// cout<<t[top]<<endl;
int n=t[top-1],m=t[top];
top--;
if(s[i]=='+') t[top]=n+m;
else if(s[i]=='-') t[top]=n-m;
else if(s[i]=='*') t[top]=n*m;
else if(s[i]=='/') t[top]=n/m;
}
}
i++;
}
return t[top];
}
int main()
{
getline(cin,s);
cout<<TWT(s);
return 0;
}