这道题可以使用Set来去除重复元素,然后将结果放入一个List中并排序输出。
复制
具体代码如下(Java实):
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner(); Set<integer> set = new HashSet<>(); for (int i = 0; i < n; ) { int num = scanner.nextInt(); .add(num); } List<integer> list = new ArrayList<>(); Collections.sort(list); for (int num : list) { System.out(num); } } }
复制
你可以根据自己的需求调整输入和输出的方式。