你好,你的代码写的很好,但是有一个小小的问题:
```cpp
a[p]+=a[p]*10+(st[i]-'0');
```
多打了一个'+',去掉就过了。
完整代码:
```cpp
#include<iostream>
#include<string>
using namespace std;
string st;
int a[5];
int p=1;
int t;
bool b;
int main(){
getline(cin,st);
for(int i=0;i<=st.size()-1;i++){
if(st[i]>='0'&&st[i]<='9'){
a[p]=a[p]*10+(st[i]-'0');
}
if(st[i]=='+'){
b=true;
p++;
}
if(st[i]=='-'){
b=false;
p++;
}
if(st[i]=='?'){
t=p;
}
if(st[i]=='='){
p++;
}
}
if(b){
if(t==1){
a[t]=a[3]-a[2];
}else if(t==2){
a[t]=a[3]-a[1];
}else if (t==3){
a[t]=a[1]+a[2];
}
}else{
if(t==1){
a[t]=a[3]+a[2];
}else if(t==2){
a[t]=a[1]-a[3];
}else if(t==3){
a[t]=a[1]-a[2];
}
}
cout<<a[t]<<endl;
return 0;
}
```
这么好的代码错在了这里有点可惜。。。
by lhz123bc @ 2023-11-10 21:57:07