样例和第一个点都是对的,但全是WA,哪位大佬看看
查看原帖
样例和第一个点都是对的,但全是WA,哪位大佬看看
30345
tanner楼主2023/5/29 17:10
#include <bits/stdc++.h>
using namespace std;
char s[105] , f;
int x,y,n;
int maxn = -1 , minn = 1 << 30 ;

void init()//输入 
{
	int cnt = 0 , i = 0 , temp = 0;
	bool flag = true;
	fgets(s,sizeof(s),stdin);
	if(s[0] < '0' || s[0] > '9') f = s[0] , i  = 2;
	int len = strlen(s);
	x = 0 , y = 0;
	for(;i < len; i++)//拆分字符串,转成数字
	{
		if(s[i] != ' ' && s[i] != '\n')
		{
			temp *= 10;
			temp += int(s[i] - 48);
		}
		else 
		{
			if(flag) x = temp , flag = false;
			else y = temp;
			temp = 0;
		}
	}
	if(temp != 0) y = temp;//最后一次的字符串没有换行符 
}
int cnt(int z)
{
	int sum = 0;
	while(z)
	{
		z /= 10;
		sum++;
	}
	return sum;
}
int main()
{
	int ans;
	scanf("%d\n",&n);
	for(int i = 1;i <= n;i++)
	{
		init();
		ans = 0;
		if(f == 'a') ans = x + y , cout<<x<<"+"<<y<<"="<<ans<<endl , cout<<2+cnt(x)+cnt(y)+cnt(ans)<<endl;
		else if(f == 'b')
		{
			ans = x - y ;
			cout<<x<<"-"<<y<<"="<<ans<<endl;
			if(ans >= 0) cout<<2+cnt(x)+cnt(y)+cnt(ans)<<endl;
			else cout<<3+cnt(x)+cnt(y)+cnt(ans)<<endl;
		} 
		else ans = x * y , cout<<x<<"*"<<y<<"="<<ans<<endl , cout<<2+cnt(x)+cnt(y)+cnt(ans)<<endl;
	} 
	return 0;
 } 
2023/5/29 17:10
加载中...