狼盟梦 @ 2020-07-02 09:39:19
#include<bits/stdc++.h>
using namespace std;
stack<char>stk;
int main()
{
string s;
int i=0,sum=0;
getline(cin,s);
while(s[i]!='@')
{
while(s[i]>='0'&&s[i]<='9')
{
sum=sum*10+s[i]-'0';
i++;
}
if(s[i]==' ')
{
stk.push(sum);
sum=0;
i++;
}
else
{
int a,b;
a=stk.top();
stk.pop();
b=stk.top();
stk.pop();
switch(s[i])
{
case '+': stk.push(a+b);break;
case '-': stk.push(b-a);break;
case '*': stk.push(a*b);break;
case '/': stk.push(b/a);break;
}
i++;
}
cout<<stk.top();
return 0;
}
}
/**/
by HearTheWindSing @ 2020-07-02 09:42:27
@Miru 这两行为啥在while里
cout<<stk.top();
return 0;
by KaguyaH @ 2020-07-02 10:08:59
@Miru
stack <char> stk
(?)
by 狼盟梦 @ 2020-07-03 09:50:47
谢谢大佬们的帮助 我这题过了