其他分享
首页 > 其他分享> > 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);
        }
    }
}

标签:play,Scanner,int,arr,System,Snuke,game,cnt,sc
来源: https://blog.csdn.net/qq_53324833/article/details/119379002