zhanxian @ 2021-01-24 18:44:18
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,al=0,cd=2;
char b[10000];
cin>>a;
int j=1;
for(int i=0;i<=a;i++){
gets(b);
char f;
int c=0,d=0;
if(b[0]=='a'||b[0]=='b'||b[0]=='c'){
f=b[0];
al=1;
}
//cout<<b;
if(f=='a'){
if(al==1) j=2;
else j=0;
//cout<<b[j]<<endl;
while(b[j]!=' '){
c+=b[j]-'0';
c*=10;
//cout<<"C"<<c<<" "<<j<<endl;
j++;
cd++;
}
j++;
while(b[j]!='\0'){
d+=b[j]-'0';
d*=10;
// cout<<d<<" "<<j<<endl;
j++;
cd++;
}
int e=(c/10)+(d/10);
while(e!=0){
e/=10;
cd++;
}
printf("%d+%d=%d\n%d\n",c/10,d/10,(c+d)/10,cd);
al=0;
}
if(f=='b'){
if(al==1) j=2;
else j=0;
//cout<<b[j]<<endl;
while(b[j]!=' '){
c+=b[j]-'0';
c*=10;
//cout<<"C"<<c<<" "<<j<<endl;
j++;
cd++;
}
j++;
while(b[j]!='\0'){
d+=b[j]-'0';
d*=10;
// cout<<d<<" "<<j<<endl;
j++;
cd++;
}
int e=(c/10)-(d/10);
if(e<0) cd++;
while(e!=0){
e/=10;
cd++;
}
printf("%d-%d=%d\n%d\n",c/10,d/10,(c-d)/10,cd);
al=0;
}
if(f=='c'){
if(al==1) j=2;
else j=0;
//cout<<b[j]<<endl;
while(b[j]!=' '){
c+=b[j]-'0';
c*=10;
//cout<<"C"<<c<<" "<<j<<endl;
j++;
cd++;
}
j++;
while(b[j]!='\0'){
d+=b[j]-'0';
d*=10;
// cout<<d<<" "<<j<<endl;
j++;
cd++;
}
int e=(c/10)*(d/10);
while(e!=0){
e/=10;
cd++;
}
printf("%d*%d=%d\n%d\n",c/10,d/10,(c*d)/100,cd);
al=0;
}
cd=2;
}
}
样例没有问题,测试点1也没有,看是全WA,求解555
by _caiji_ @ 2021-01-24 19:02:57
因为gets会读进\r,所以请使用scanf读入字符串