ace_12138 @ 2023-11-22 21:32:50
//如何输入:
//如何实现:
#include<string.h>
#include <stdio.h>
int main()
{ char x;//用于储存运算类型
int n,a,b;
scanf("%d",&n);
getchar();
char s[10],tem[100];
for(int i=0;i<n;i++){
scanf("%c",&s[0]);
if(s[0]<='c'&&s[0]>='a'){
scanf("%d%d",&a,&b);
x=s[0];
}else{
sscanf(s,"%d",a);
scanf("%d",&b);
}
sprintf(tem,"%d+%d=%d",a,b,a+b);
if(x=='a'){
printf("%d+%d=%d\n",a,b,a+b);
printf("%d\n",strlen(tem));
} else if(x=='b'){
printf("%d-%d=%d\n",a,b,a-b);
printf("%d\n",strlen(tem));
}else if(x=='c'){
printf("%d*%d=%d\n",a,b,a*b);
printf("%d\n",strlen(tem));
}
}
return 0;
}
by BGM114514 @ 2023-11-22 21:38:02
@ace_12138 scanf中%c会读入Enter,加个getchar试试
by ace_12138 @ 2023-11-22 21:42:52
@BGM114514 在哪一行加getchar() 我试过把第9行的放到12行后但是不对 不知道在哪个位置加才对
by BGM114514 @ 2023-11-22 21:45:30
@ace_12138 每次%c之前都要getchar
by 御坂13906号 @ 2023-11-22 23:08:20
@BGM114514 %c前加个空格就行,可以过滤空白字符 @ace_12138