abcd231 @ 2021-01-27 19:14:52
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
getchar();
int czs[52][4]={0};
int k=2;
int j=0,i=0;
char ch;
char fh[52];
int m=0;
for(i=0;i<n;i++)
{
j=0;
k=2;
m=0;
while(1)
{
ch=getchar();
if(ch=='\n')
break;
if(ch>='0'&&ch<='9')
{
czs[i][j]=czs[i][j]*10+ch-'0';
if(m==0)
fh[i]='+';
k++;
}
if(ch==' ')
j++;
if(ch>='a'&&ch<='d')
{
switch (ch)
{
case 'c':fh[i]='*';break;
case 'b':fh[i]='-';break;
case 'a':fh[i]='+';break;
}
j--;
}
m=1;
}
switch (fh[i])
{
case '+':
{
czs[i][2]=czs[i][0]+czs[i][1];
if(czs[i][2]/10==0)
k++;
else if(czs[i][2]/100==0)
k+=2;
else if(czs[i][2]/1000==0)
k+=3;
else if(czs[i][2]/10000==0)
k+=4;
}break;
case '-':
{
czs[i][2]=czs[i][0]+czs[i][1];
if(czs[i][2]<0)
k++;
int x=-czs[i][2];
if(x/10==0)
k++;
else if(x/100==0)
k+=2;
else if(x/1000==0)
k+=3;
else if(x/10000==0)
k+=4;
}break;
case '*':
{
czs[i][2]=czs[i][0]*czs[i][1];
if(czs[i][2]/10==0)
k++;
else if(czs[i][2]/100==0)
k+=2;
else if(czs[i][2]/1000==0)
k+=3;
else if(czs[i][2]/10000==0)
k+=4;
else if(czs[i][2]/100000==0)
k+=5;
else if(czs[i][2]/1000000==0)
k+=6;
else if(czs[i][2]/10000000==0)
k+=7;
else if(czs[i][2]/100000000==0)
k+=8;
}break;
}
czs[i][3]=k;
k=0;
}
for(i=0;i<n;i++)
{
printf("%d%c%d=%d\n%d\n",czs[i][0],fh[i],czs[i][1],czs[i][2],czs[i][3]);
}
return 0;
}