终于在vijos上提交了我的第一个java代码,是NOIP2006T1(明明的随机数)
虽然题很简单,但是我终于用java代码提交正确了。。。好感动
代码如下:
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner cin = new Scanner(System.in); final int maxn = 101; int[] a = new int [maxn]; int n = cin.nextInt(); for(int i = 0 ; i < n ; i ++) a[i] = cin.nextInt(); Arrays.sort(a,0,n); int ans = 1; for(int i = 1 ; i < n ; i ++){ if( a[i] != a[i-1]){ ans++; } } System.out.println(ans); System.out.print(a[0]); for(int i = 1 ; i < n ; i ++){ if( a[i] != a[i-1]){ System.out.print(" "+a[i]); } } cin.close(); } }
时间: 2024-10-29 02:08:12