洛谷 P1059 明明的随机数 (JAVA)

洛谷 P1059 明明的随机数

import java.util.Scanner;
import java.util.TreeSet;
import java.util.Iterator;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        TreeSet<Integer> ts = new TreeSet<>();
        for(int i = 0; i < n; i++) {
            ts.add(scan.nextInt());
        }
        System.out.println(ts.size());
        Iterator<Integer> it = ts.iterator();
        while(it.hasNext()) {
            System.out.print(it.next());
            if(it.hasNext()) System.out.print(" ");
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/fromneptune/p/12222250.html