danlao @ 2023-10-28 08:08:18
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
int n,a,b,c;
char last,s[110],ans[110];
scanf("%d\n",&n);
while(n--){
fgets(s,sizeof(s),stdin);
if(s[0]=='a'or s[0]=='b' or s[0]=='c') last=s[0],s[0]=' ';
sscanf(s,"%d %d",&a,&b);
switch(last){
case'a':c=a+b;sprintf(ans,"%d+%d=%d",a,b,c);break;
case'b':c=a-b;sprintf(ans,"%d-%d=%d",a,b,c);break;
case'c':c=a*b;sprintf(ans,"%d*%d=%d",a,b,c);break;
}
printf("%s\n%d\n",ans,strlen(ans));
}
return 0;
}
by Vocaloid世末歌者 @ 2023-10-28 08:22:18
@yaodiguoan 捕捉!
还有你用的什么语言,调成C++14试试
by danlao @ 2023-10-28 08:47:42
自动识别
by danlao @ 2023-10-28 08:48:47
@CPlusPlusOnMars_star 没听懂你在说啥
by Andy_AC @ 2023-10-28 10:27:20
@yaodiguoan
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b,c;
char last,s[110],ans[110];
scanf("%d\n",&n);
while(n--){
fgets(s,sizeof(s),stdin);
if(s[0]=='a'or/*不要用or 用|| or只要左右两面没打空格就错了!*/ s[0]=='b' or s[0]=='c') last=s[0],s[0]=' ';
sscanf(s,"%d %d",&a,&b);
switch(last){
case'a':c=a+b;sprintf(ans,"%d+%d=%d",a,b,c);break;
case'b':c=a-b;sprintf(ans,"%d-%d=%d",a,b,c);break;
case'c':c=a*b;sprintf(ans,"%d*%d=%d",a,b,c);break;
}
printf("%s\n%d\n",ans,strlen(ans));
}
return 0;
}
by danlao @ 2023-10-28 11:15:41
@Andy_AC 对耶,谢谢!!!