题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
这题的主要难度在于读题
1. 首先要明确数据的输入是一组一组进行输入的
2. 子问题就是去重+排序问题
3. 使用set去重,然后转换为list进行排序操作并输出
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int length = sc.nextInt();
Set<Integer> set = new HashSet<>();
for(int i = 0; i<length; i++){
set.add(sc.nextInt());
}
ArrayList<Integer> list = new ArrayList<>(set);
Collections.sort(list);
for(int num:list){
System.out.println(num);
}
}
}
}

