BUPT-比较奇偶数个数

题目链接

https://www.nowcoder.com/practice/188472f474d5421cb8218b8ad561023b?tpId=67&tqId=29636&tPage=1&ru=/kaoyan/retest/1005&qru=/ta/bupt-kaoyan/question-ranking

题目描述

第一行输入一个数,为n,第二行输入n个数,这n个数中,如果偶数比奇数多,输出NO,否则输出YES。

输入描述:

输入有多组数据。
每组输入n,然后输入n个整数(1<=n<=1000)。

输出描述:

如果偶数比奇数多,输出NO,否则输出YES。
示例1

输入

复制
5
1 5 2 4 3

输出

复制
YES

题解:

#include <iostream>
using namespace std;
int main(){
	int n, a[1000];
	while(cin >> n){
		int x = 0, y = 0;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			if(a[i] % 2 == 0)
				x++;
			else
				y++; 
		}
		if(x > y)
			cout << "NO" << endl;
		else
			cout << "YES" << endl;
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/reigns_/article/details/80986093