求大佬指教
查看原帖
求大佬指教
118184
In_blue楼主2020/5/14 12:41

本机运行没问题,为什么交上去会WA??

code:

#include<cctype>
#include<cstdio>
using namespace std;
char s;
inline long long read()
{
	long long a=0,b=1;
	char c=getchar();
	if(c=='a'||c=='b'||c=='c')s=c,c=getchar();
	while(!isdigit(c)){if(c=='-')b=-1;c=getchar();}
	while(isdigit(c))
	{
		a=(a<<3)+(a<<1)+(c^48);
		c=getchar();
	}
	return a*b;
}
inline void write(long long a)
{
	if(a<0)putchar('-'),a=-a;
	if(a>=10)write(a/10);
	putchar(a%10+48);
	return;
}
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	{
		int a=read(),b=read();
		if(s=='a')
		{
			write(a);
			putchar('+');
			write(b);
			putchar('=');
			write(a+b);
			puts("");
			int ans=0,num=a+b;
			while(a)a/=10,ans++;
			while(b)b/=10,ans++;
			while(num)num/=10,ans++;
			write(ans+2);
			puts("");
		}
		if(s=='b')
		{
			write(a);
			putchar('-');
			write(b);
			putchar('=');
			write(a-b);
			puts("");
			int ans=0,num=a-b;
			if(num<=0)ans++,num=-num;
			while(a)a/=10,ans++;
			while(b)b/=10,ans++;
			while(num)num/=10,ans++;
			write(ans+2);
			puts("");
		}
		if(s=='c')
		{
			write(a);
			putchar('*');
			write(b);
			putchar('=');
			write(a*b);
			puts("");
			int ans=0,num=a*b;
			while(a)a/=10,ans++;
			while(b)b/=10,ans++;
			while(num)num/=10,ans++;
			write(ans+2);
			puts("");
		}
	}
	return 0;
}

2020/5/14 12:41
加载中...