shipeiqian @ 2022-08-17 14:45:41
#include <bits/stdc++.h>
using namespace std;
string c;
char op;
int n,ans=0,a,b;
int len(int n){
int cnt;
if(n==0)return 1;
if(n>0){
cnt=0;
while(n){
n/=10;
cnt++;
}
return cnt;
}
else{
cnt=1;
n=-n;
while(n){
n/=10;
cnt++;
}
return cnt;
}
}
int main(){
cin >>n;
while(n--){
ans=0;
cin >>c;
if(c[0]=='a'){
cin >>a >>b;
cout <<a <<"+" <<b <<"=" <<a+b <<"\n";
ans=len(a+b)+2;
op=c[0];
}
else if(c[0]='b'){
cin >>a >>b;
cout <<a <<"-" <<b <<"=" <<a-b <<"\n";
ans=len(a-b)+2;
op=c[0];
}
else if(c[0]='c'){
cin >>a >>b;
cout <<a <<"*" <<b <<"=" <<a*b <<"\n";
ans=len(a*b)+2;
op=c[0];
}
else{
cin >>b;
a=0;
for(int i=0;i<c.size();i++)a=a*10+c[i]-'0';
if(op=='a'){
cout <<a <<"+" <<b <<"=" <<a+b <<"\n";
ans=len(a+b)+2;
}
else if(op=='b'){
cout <<a <<"-" <<b <<"=" <<a-b <<"\n";
ans=len(a-b)+2;
}
else if(op=='c'){
cout <<a <<"*" <<b <<"=" <<a*b <<"\n";
ans=len(a*b)+2;
}
}
ans=ans+len(a)+len(b);
cout <<ans <<"\n";
}
return 0;
}
by zhou_reset_qihao @ 2022-08-17 14:56:08
你那里是if c[0]=='c' 和 c[0]=='b'