解题思路:
注意事项:开局10连wa,我以为是其他错了,没想到忘判断i==0的条件了
参考代码:
package cWeb.acm; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class 明明的随机数 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); List<Integer> list = new ArrayList<>(); int N = in.nextInt(); int num; for (int i = 0; i < N; i++) { num = in.nextInt(); if(i==0) list.add(num); if(i!=0 && !list.contains(num)) list.add(num); } int temp; for (int i = 0; i < list.size(); i++) { for (int j = 0; j < list.size()-i-1; j++) { if(list.get(j)>list.get(j+1)) { temp = list.get(j); list.set(j, list.get(j+1)); list.set(j+1, temp); } } } System.out.println(list.size()); for (int i = 0; i < list.size()-1; i++) { System.out.print(list.get(i)+" "); } System.out.print(list.get(list.size()-1)); } }
0.0分
2 人评分