algorithm Training clearly random numbertime limit: 1.0s memory limit: 256.0MBProblem description obviously want to ask some students in the school to do a questionnaire survey, in order to the objectivity of the experiment, he first used a computer to generate N 1 to 1000 random integer (n≤100), for the repeated numbers, only one, the rest of the same number is removed, the different numbers correspond to different student's number. Then the numbers from small to large sorting, in line with the order to find students to do the investigation. Please help clearly to complete the "go to Heavy" and "sort" work. Input format input has 2 lines, the 1th behavior 1 positive integers, which indicates the number of random numbers generated:
N
The 2nd line has n spaces separated by a positive integer, which is the resulting random number. Output format output is also 2 lines, the 1th behavior 1 positive integer m, representing the number of different random numbers. The 2nd behavior is a positive integer separated by a space, which is a different random number from small to large sequence. Sample Input 10
20 40 32 67 40 20 89 300 400 15 Sample output 8
15 20 32 40 67 89 300 400 source of the topic 13 cc Lee excerpt from noip06pj01
Importjava.util.Arrays;ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in); while(Sc.hasnext ()) {intn=Sc.nextint (); intb[]=New int[n]; for(inti=0;i<n;i++) {B[i]=Sc.nextint (); } arrays.sort (b); for(inti=0;i<n;i++){ for(intj=i+1;j<n;j++){ if(B[i]==b[j] && b[i]!=-1) B[j]=-1; } } intSum=0; for(inti=0;i<n;i++){ if(B[i]!=-1) {sum++; }} System.out.println (sum); for(inti=0;i<n;i++){ if(B[i]!=-1) System.out.print (B[i]+" "); } } }}
Algorithm training clearly random number