和题解的答案一样,但是WA,求大佬看看
查看原帖
和题解的答案一样,但是WA,求大佬看看
395486
KH20020907楼主2020/11/21 20:37
#include<cmath>
#include<string.h>
int howmuch(int);
int main()
{
	int k,n,i,j,b1,b2,t;
	char a[20],w;
	scanf("%d\n",&n);
	for(i=1;i<=n;i++)
	{	
	memset(a,0,sizeof(a));
		gets(a);
		b1=0,b2=0;
		if(a[0]>='a'&&a[0]<='c')j=2,w=a[0];
		else j=0;
		t=0;
		for(;j<strlen(a);j++)
		{
			if(a[j]==' ')
				t=1;
			else 
			{
				if(t==0)b1=b1*10+(a[j]-'0');
				else b2=b2*10+(a[j]-'0');
			}
		}
		if(w=='a')printf("%d+%d=%d\n",b1,b2,k=b1+b2);
		else if(w=='b')printf("%d-%d=%d\n",b1,b2,k=b1-b2);
		else if(w=='c')printf("%d*%d=%d\n",b1,b2,k=b1*b2);
		if(k<0)k*=10;	
		printf("%d\n",howmuch(b1)+howmuch(b2)+howmuch(k)+2);	
	}
	return 0;
 } 
 int howmuch(int n)
 {int i=0;
 	while(n!=0)
 	{
 		n/=10;
 		i++;
	 }
	 return i;
 }
2020/11/21 20:37
加载中...