Snuke has decided to play a game using cards

Snuke has decided to play a game using cards

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            //判断种类数
            Arrays.sort(arr);
            int cnt = 1;
            int x = arr[0];
            for (int i = 0; i < n; i++) {
                if(x != arr[i]) {
                    cnt++;
                    x = arr[i];
                }
            }
            
            if(cnt % 2 == 0) System.out.println(cnt-1);
            else System.out.println(cnt);
        }
    }
}
上一篇:OCJP(1Z0-851) 模拟题分析(六)over


下一篇:偏序序列变换规律新探