mianm @ 2021-11-27 20:47:47
#include<stdio.h>
#include<math.h>
int weishu(int n);
int isalpha(char a);
int main()
{
int i, b[50], c[50], r=0;
char a[50];
scanf("%d",&i);
getchar();
for (int j = 0;j < i;j++)
{
scanf("%c", &a[j]);
if (isalpha(a[j]))
scanf(" %d %d", &b[j], &c[j]);
else
{
scanf("%d %d", &b[j], &c[j]);
int t = a[j] - '0';
b[j] = t * pow(10, weishu(b[j])) + b[j];
a[j] = a[j - 1];
}
getchar();
}
for (int j = 0;j < i;j++)
{
switch (a[j])
{
case'a':
{
r = b[j] + c[j];
printf("%d+%d=%d\n", b[j], c[j], r);
}
break;
case'b':
{
r = b[j] - c[j];
printf("%d-%d=%d\n", b[j], c[j], r);
}
break;
case'c':
{
r = b[j] * c[j];
printf("%d*%d=%d\n", b[j], c[j], r);
}
break;
}
int w = weishu(b[j]) + weishu(c[j]) + weishu(r) + 2;
if (j != i - 1)
printf("%d\n", w);
else
printf("%d", w);
}
return 0;
}
int weishu(int n)
{
int c = 1;
if (n / 10)
c = 2;
if (n / 100)
c = 3;
if (n / 1000)
c = 4;
if (n < 0)
c += 1;
return c;
}
int isalpha(char a)
{
int c = 0;
if (a>='a'&& a<='z')
c = 1;
return c;
}
by _l_l_l_l_l_ @ 2021-11-27 21:30:34
请看输出格式