那可能是读入的问题,有可能每行只有两个数,却读入了三个,就可能吧下一个数字吸收掉,例如
```
3
+ 1 2
3 4
5 6
```
by buzhidao0123 @ 2023-08-31 21:48:25
楼上正解,应特判或使用sscanf
```cpp
#include<bits/stdc++.h>
using namespace std;
char c;
int a,d,e,f;
char s[5050],g[1000];
int main(){
cin>>a;
while(a--){
cin>>g;
if(g[0]!='a'&&g[0]!='b'&&g[0]!='c'){
sscanf(g,"%d",&d);
cin>>e;
}else{
c=g[0];
cin>>d>>e;
}
if(c=='a'){
sprintf(s,"%d+%d=%d",d,e,d+e);
}else if(c=='b'){
sprintf(s,"%d-%d=%d",d,e,d-e);
}else{
sprintf(s,"%d*%d=%d",d,e,d*e);
}
cout<<s<<endl<<strlen(s)<<endl;
}
return 0;
}
by Null_h @ 2023-08-31 21:50:51