table of Contents
Title description
Obviously he wanted to invite some students to do a questionnaire survey in school. For the objectivity of the experiment, he first generated N random integers between 1 and 1000 (N≤1000). For the repeated numbers, only Keep one and remove the rest of the same number. Different numbers correspond to different student numbers. Then sort these numbers from smallest to largest, and go to classmates to investigate in the order. Please help you clearly complete the work of "de-duplication" and "sorting" (there may be multiple sets of data in the same test case, I hope you can handle it correctly).
Note: The test case guarantees the correctness of the input parameters, and the answerer does not need to verify. There is more than one set of test cases.
When there is no new input, the input ends.
Enter description
Note: The input may have multiple sets of data. Each group of data consists of multiple rows, the first row first enter the number N of random integers, and the next N rows then enter the corresponding number of integers. Please see the "example" below for the specific format.
Output description
Return multiple rows, the processed result
Example 1
enter
3
2
2
1
11
10
20
40
32
67
40
20
89
300
400
15
Output
1
2
10
15
20
32
40
67
89
300
400
Description
Sample input explanation: The sample has two sets of tests. The first group is 3 numbers, namely: 2, 2, 1. The second group is 11 numbers, respectively: 10, 20, 40, 32, 67, 40, 20, 89, 300, 400, 15.
Question ideas
Numbers within 1000 deduplicate + sort, no doubt, use bucket sort
AC code
#include<iostream>
using namespace std;
int main(){
int N;
int n;
while(cin >> N){
int num[1001] = {0};
while(N--){
cin >> n;
num[n] = 1;
}
for(int i=0; i<1001; i++){
if( num[i]==1 ){
cout << i <<endl;
}
}
}
return 0;
}