forked from Doragd/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
数组数组数组
Description
- 明明生成了$N$个1到500之间的随机整数。请你删去其中重复的数字,即相同的数字只保留一个,把其余相同的数去掉,然后再把这些数从小到大排序,按照排好的顺序输出。
- 数据范围: $1 \le n \le 1000 $ ,输入的数字大小满足
$1 \le val \le 500 $ - 循环遍历
- 子循环判断新录入的
- 注意跳出循环continue
- 再次循环treeSet
public class Main {
public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
int generateCount = in.nextInt();
final SortedSet<Integer> treeSet = new TreeSet<>();
for (int i = 0; i < generateCount; i++) {
Scanner scanner = new Scanner(System.in);
if (in.hasNextInt()) {
treeSet.add(in.nextInt());
continue;
}
}
treeSet.spliterator().forEachRemaining(e -> {
System.out.println(e.intValue());
});
}
}Metadata
Metadata
Assignees
Labels
数组数组数组