Hunteryan @ 2024-07-11 20:52:08
本地也过不了,我也没开数组啊
#include<bits/stdc++.h>
using namespace std;
int len(int k){
int l=0;
while(k>=1){
k/=10;
l++;
}
return l;
}
string s;
int n;
char todo;
int main() {
cin >> n;
for(int i = 1;i <= n;i++){
getline(cin,s);
int st=0;
if(s[0]>'9'||s[0]<'0'){
todo=s[0];
st=2;
}
bool f=0;
int a=0,b=0;
for(int j = st;j <= s.size()-1;j++){
if(s[j]==' '){
f=1;
continue;
}
if(f==0){
a*=10;
a+=s[i]-'0';
}else{
b*=10;
b+=s[i]-'0';
}
}
int ans=0;
if(todo=='a'){
ans=a+b;
}
if(todo=='b'){
ans=a-b;
}
if(todo=='c'){
ans=a*b;
}
cout << a;
if(todo=='a'){
cout << "+";
}
if(todo=='b'){
cout << "-";
}
if(todo=='c'){
cout << "*";
}
cout << b << "=" << ans << endl;
cout << len(a)+len(b)+len(ans)+2 << endl;
}
return 0;
}
by lpk1118 @ 2024-07-12 17:04:06
你不是AC了吗?建议自删