跟你沟通 @ 2022-10-28 22:10:18
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int cal_len(int num)
{
int t=0;
if(num==0)
return 0;
else if(num>0)
while(num)
{
t++;
num/=10;
}
else
{
++t;
num*=-1;
while(num)
{
t++;
num/=10;
}
}
return t;
}
int main()
{
char str[100],c;
int a=0,b=0,n,x;
scanf("%d",&n);getchar();
while(n-->0)
{
memset(str,0,100);
scanf("%s",str);
switch(str[0])
{
case 'a':
scanf("%d%d",&a,&b);
printf("%d+%d=%d\n",a,b,a+b);
x=cal_len(a+b)+2;
c=str[0];
break;
case 'b':
scanf("%d%d",&a,&b);
printf("%d-%d=%d\n",a,b,a-b);
x=cal_len(a-b)+2;
c=str[0];
break;
case 'c':
scanf("%d%d",&a,&b);
printf("%d*%d=%d\n",a,b,a*b);
x=cal_len(a*b)+2;
c=str[0];
break;
default:
int k=strlen(str);
a=0;
for(int i=0;i<k;++i)
a=a*10+str[i]-'0';
scanf("%d",&b);
switch(c)
{
case 'a':
printf("%d+%d=%d\n",a,b,a+b);
x=cal_len(a+b)+2;
break;
case 'b':
printf("%d-%d=%d\n",a,b,a-b);
x=cal_len(a-b)+2;
break;
case 'c':
printf("%d*%d=%d\n",a,b,a*b);
x=cal_len(a*b)+2;
break;
}
break;
}
x+=cal_len(a)+cal_len(b);
printf("%d\n",x);
}
return 0;
}
by greenwood2022 @ 2022-11-17 16:15:39
哥们解决了吗,我和你一样的情况
by potato_5 @ 2022-12-15 18:09:09
没考虑0吧 if(num==0) return 0;改成 return 1;就可以了