操作数可能是两位数三位数,所以不能单字符入栈
这是我的代码
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
stack<long long>a;
long long e=0;/*暂存数字的容器*/
for(long long t=0;t<s.size();t++){
if(s[t]>='0'&&s[t]<='9')e=e*10+(s[t]-'0');/*如果是数字就输入到容器(因为操作数可能不止一位)*/
if(s[t]=='.'){
a.push(e);
e=0;/*如果是结束符就把数字入栈,清空容器*/
}
if(s[t]=='+'||s[t]=='-'||s[t]=='*'||s[t]=='/'){
/*x和y的顺序是反过来的 */
long long y=a.top();
a.pop();
long long x=a.top();
a.pop();
if(s[t]=='+')a.push(x+y);
if(s[t]=='-')a.push(x-y);
if(s[t]=='*')a.push(x*y);
if(s[t]=='/')a.push(x/y);
}
if(s[t]=='@')cout<<a.top();
}
return 0;
}
```
by Lzc0316 @ 2023-08-28 11:33:04
@[Lzc0316](/user/976531) 好的谢谢大佬
by XinFengIneverleft @ 2023-08-28 19:13:49