首页 > 试题广场 >

比较奇偶数个数

[编程题]比较奇偶数个数
  • 热度指数:5367 时间限制: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

①列表中显示的题目与打开超链接后显示的题目不一样
②实际题目是重复了的,以下代码就是昨晚做过的题,复制粘贴运行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");
            }
        }
    }
}
编辑于 2018-05-12 19:23:56 回复(0)
 import java.util.Scanner;

/**
 * Created by fhqplzj on 17-2-19 at 下午8:51.
 */
public class Trip {
    private static String process(double x, int n) {
        double y = x;
        for (int i = 0; i < n; i++) {
            y = 2.0 / 3 * y + x / (3 * y * y);
        }
        return String.format("%.6f", y);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextDouble()) {
            double x = scanner.nextDouble();
            int n = scanner.nextInt();
            System.out.println(process(x, n));
        }
    }
}
编辑于 2017-02-19 20:55:36 回复(0)

问题信息

难度:
2条回答 4699浏览

热门推荐

通过挑战的用户