floatingincodes @ 2024-01-08 10:19:56
#include<stdio.h>
#include<string.h>
char x[1001]={};
int main()
{
int i,t=0,N,k,m=0,n=0,s,u=0,j;
scanf("%d",&N);
getchar();
for(i=0;i<N;i++){
fgets(x,1001,stdin);
int l=strlen(x);
//printf("%d",l);
for(j=0;j<l;j++){
if(x[j]>='0'&&x[j]<='9'&&t==0){
m*=10;m+=x[j]-'0';
}
if(x[j-1]>='0'&&x[j-1]<='9'&&x[j]==' ') {
t=1;
}
else if(x[j]>='0'&&x[j]<='9'&&t==1){
n*=10;n+=x[j]-'0';
}
}
if(x[0]=='a'){
k=1;
s=m+n;
do{
s/=10;u++;
}while(s);
s=m+n;
}
else if(x[0]=='b'){
k=2;
s=m-n;
do{
s/=10;u++;
}while(s);
s=m-n;
}
else if(x[0]=='c'){
k=3;
s=m*n;
do{
s/=10;u++;
}while(s);
s=m*n;
}
else{
if(k==1){
s=m+n;
do{
s/=10;u++;
}while(s);
s=m+n;
}
else if(k==2){
s=m-n;
do{
s/=10;u++;
}while(s);
s=m-n;
}
else{
s=m*n;
do{
s/=10;u++;
}while(s);
s=m*n;
}
}
if(k==1) printf("%d+%d=%d\n",m,n,s);
else if(k==2) printf("%d-%d=%d\n",m,n,s);
else if(k==3) printf("%d*%d=%d\n",m,n,s);
if(s<0){
if(x[0]>='0'&&x[0]<='9') printf("%d\n",l+u+1);
else printf("%d\n",l-1+u);
}
else{
if(x[0]>='0'&&x[0]<='9') printf("%d\n",l+u);
else printf("%d\n",l-2+u);
}
u=0;t=0;m=0;n=0;
}
return 0;
}
by xk2013 @ 2024-01-08 11:32:45
你是不是没有考虑 int
与 char
的类型转换?
by floatingincodes @ 2024-01-08 19:53:34
@xk2013 哪一步呢?我在自己电脑上跑样例的结果跟他给的还是一模一样的