//话说我也想做立方根的题目
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
while(cin>>n){
int b,o_num=0,e_num=0;
for(int i=0;i<n;i++){
cin>>b;
if(b%2==0)
e_num++;
else
o_num++;
}
if(o_num<e_num)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
} ①列表中显示的题目与打开超链接后显示的题目不一样
②实际题目是重复了的,以下代码就是昨晚做过的题,复制粘贴运行AC一气呵成
③奇偶数英语:奇数odd,偶数even
import java.util.Scanner;
/**
* @author Allen_Hua
* @create_time 创建时间:May 11, 2018 9:51:56 PM 类说明
*/
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
int[] data = new int[n];
for (int i = 0; i < data.length; i++) {
data[i] = scan.nextInt();
}
int jiShu = 0, ouShu = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] % 2 == 0) {
ouShu++;
} else {
jiShu++;
}
}
if (ouShu > jiShu) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
#include<stdio.h>
int main (){//the shorter,the better.
int x,n;double r;
for(;~scanf("%d%d",&x,&n);)
for(r=x;n>0&&(r = r*2.0/3+x/(3.0*r*r));n--,n==0?printf("%.6lf\n",r):0);
}
#include <iostream>
#include <string>
using namespace std;
int main(){
int n;
const string ANS_STRING[] = {"YES", "NO"};
while(cin >> n){
int odd = 0, x;
for(int i = 0; i < n; i++) {
cin >> x;
odd += x & 0x1;
}
cout << ANS_STRING[odd < n - odd] << endl;
}
return 0;
}
这是我想到的一种比较优雅的解法,整个代码省略了if语句,而且不用单独用两个变量记录奇数和偶数。 import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()){
int n = sc.nextInt();
int even = 0;
int odd = 0;
int num;
for (int i = 0; i < n; i++){
num = sc.nextInt();
if (num % 2 == 0){
even++;
} else {
odd++;
}
}
if (even > odd){
System.out.println("Yes");
} else {
System.out.println("No");
}
}
sc.close();
}
} #include<stdio.h>
int main()
{
int i,n;
int a[1000];
int o=0;
int e=0;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]%2==0)
e++;
else
o++;
}
if(e>o)
printf("NO");
else
printf("YES");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
while(~scanf("%d", &n))
{
int count = 0;
int temp;
for(int i = 0; i < n; i++)
{
scanf("%d", &temp);
if(temp % 2 == 0)
count--;
else
count++;
}
if(count < 0)
printf("NO\n");
else
printf("YES\n");
}
} 这不是北邮的复试题吗...放错位置了吧#include<stdio.h>
int main(){
int n;
while(~scanf("%d",&n)){
//int p[n];
int cnt=0;
/*for(int i=0;i<n;i++){
scanf("%d",&p[i]);
if(p[i]%2==0)
cnt++;
else
cnt--;
}*/
int x;
while(n--){
scanf("%d",&x);
if(x%2==0) cnt++;
else cnt--;
}
if(cnt>0)
printf("NO\n");
else
printf("YES\n");
}
}
加注释的是使用数组的,也可以不使用数组。
两行n,nums=int(input()),list(map(int,input().split()))
def OddVSEven():
n = int(input())
numList = list(map(int,input().split()))
OddCount = 0
EvenCount = 0
for i in numList:
if i %2 ==0:
EvenCount +=1
else :
OddCount +=1
if EvenCount > OddCount :
print("NO")
else:
print("YES")
OddVSEven()