题目链接:
https://www.luogu.com.cn/problem/P1059
代码实例:
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int array[] = new int[a];
Random random1 = new Random();
if(a>100) {
System.out.println("错误!");
}else {
for(int i = 0;i<a;i++) {
array[i] = input.nextInt();
}
}
// 排序
Arrays.sort(array);
List<Integer> list = new ArrayList<>();
for(int i = 0;i<array.length;i++) {
if(!list.contains(array[i])) {
list.add(array[i]);
}
}
System.out.println(list.size());
for(int i = 0;i<list.size();i++) {
if(i == list.size()-1) {
System.out.print(list.get(i));
}else {
System.out.print(list.get(i)+" ");
}
}
}
}