文章

49

粉丝

49

获赞

8

访问

11.0k

头像
C++
P1869 云南大学机试题
发布于2024年3月17日 19:36
阅读数 112

#include<iostream>
#include<vector>
using namespace std;

bool is_all_even_or_all_odd(vector<int> v)
{
	if (v.front() % 2 == 0)
	{
		for (auto t : v)
		{
			if (t % 2 != 0)
			{
				return false;
			}
		}
	}
	else
	{
		for (auto t : v)
		{
			if (t % 2 == 0)
			{
				return false;
			}
		}
	}
	return true;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		vector<int> v(t);
		for (int i = 0; i < t; i++)
		{
			int x;
			cin >> x;
			v[i] = x;
		}
		if (is_all_even_or_all_odd(v))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}

	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发