CNSnowCat @ 2023-11-24 16:38:20
代码如下
#include <stdio.h>
#include <string.h>
int main(){
char list[50][20010];
int a=0, aLen=0, b=0, bLen=0, c, cLen=0, flag=0, n;
int i, j;
scanf("%d", &n);
for(i=0;i<n;i++){
getchar();
getchar();
gets(list[i]);
}
for(i=0;i<n;i++){
if(list[i][0] >= 'a'){
flag = list[i][0]-'a';
j=2;
}
else{
j=0;
}
a = b = aLen = bLen = cLen = 0;
for(;list[i][j]!=' ';j++){
a *= 10;
a += list[i][j] - '0';
aLen++;
}
j++;
for(;list[i][j]!='\0';j++){
b *= 10;
b += list[i][j] - '0';
bLen++;
}
switch(flag){
case 0:
c = a+b;
printf("%d+%d=%d\n", a, b, c);
break;
case 1:
c = a-b;
printf("%d-%d=%d\n", a, b, c);
break;
case 2:
c = a*b;
printf("%d*%d=%d\n", a, b, c);
break;
}
if(c < 0)
cLen++;
do{
c /= 10;
cLen++;
}while(c);
printf("%d\n", aLen+bLen+cLen+2);
}
return 0;
}