为什么全是WA,测试数据都通过了,求助!!!
查看原帖
为什么全是WA,测试数据都通过了,求助!!!
294363
wlimcoming楼主2021/2/14 16:00
#include<bits/stdc++.h>
using namespace std;
int getlen(int x)
{
	string a = to_string(x);
	return a.length();
}
int main()
{
	int n;
	cin >> n;
	bool flag = true;
	string s;
	char fh;
	int x1, x2, a1, a2;	
	char temp;
	cin.ignore();
	while (n--)
	{
		getline(cin, s);
		temp = s[0];
		if (!isdigit(temp))
		{
			fh = temp;
			a1=s.find(' ');
			string s2 = s.substr(a1 + 1);
			a2 = s2.find(' ');
			x1 = atoi(s2.substr(0, a2).c_str());
			x2 = atoi(s2.substr(a2 + 1).c_str());
		}
		else
		{
			a1 = s.find(' ');
			x1 = atoi(s.substr(0, a1).c_str());
			x2 = atoi(s.substr(a1 + 1).c_str());
		}
		switch (fh)
		{
		case 'a':cout << x1 << "+" << x2 << "=" << x1 + x2 << endl;
			cout << getlen(x1) + getlen(x2) + getlen(x1 + x2) + 2 << endl;
			break;
		case 'b':cout << x1 << "-" << x2 << "=" << x1 - x2 << endl;
			cout << getlen(x1) + getlen(x2) + getlen(x1 - x2) + 2 << endl;
			break;
		case 'c':cout << x1 << "*" << x2 << "=" << x1 * x2 << endl;
			cout << getlen(x1) + getlen(x2) + getlen(x1 * x2) + 2 << endl;
			break;
		}
	}
}
2021/2/14 16:00
加载中...