题库链接:https://blog.csdn.net/weixin_43905586/article/details/112438701
用时:5分钟
分享名言一句
-
One day, when you look back on your journey, you will find that the years of constant struggle were the most beautiful life.——Freud
-
有一天,当回顾自己走过的路时,你会发现这些奋斗不息的岁月,才是最美好的人生。——弗洛伊德
时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
题目描述
第一行输入一个数,为n,第二行输入n个数,这n个数中,如果偶数比奇数多,输出NO,否则输出YES。
输入描述:
输入有多组数据。
每组输入n,然后输入n个整数(1<=n<=1000)。
输出描述:
如果偶数比奇数多,输出NO,否则输出YES。
示例1
输入
5
1 5 2 4 3
输出
YES
鄙人拙见
- 直接对奇数或偶数计数
- 用总数减去即可得另一种数的个数
- 比较俩个数的大小,输出即可
C++参考代码1.0:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
int num[n];
for(int i = 0; i < n; i++)
{
scanf("%d",&num[i]);
}
int odd_count = 0;
for(int i = 0; i < n; i++)
{
if(num[i] % 2 != 0)
{
odd_count++;
}
}
int even_count;
even_count = n - odd_count;
if(even_count > odd_count)
{
printf("NO");
}
else
{
printf("YES");
}
return 0;
}