the random number of HHTime limit:1 Sec Memory limit:128 MB
submit:413 solved:60
[Submit] [Status] [Web Board]
Description
HH wants to ask some students to do a survey at school, for the objectivity of the experiment, he first generated N 1 to 1000 random integers (n≤100), for which the number of repetitions, only one, the rest of the same number to remove, different numbers correspond to the number of different students. Then the number of these numbers from small to large, according to the order of the row to find students to do the survey. Please help to complete the "Go heavy" and "sort" work. Input
There are 2 rows, and the 1th behavior is 1 positive integers, representing the number of random numbers generated:
N
The 2nd row has n a positive integer separated by a space, which is the resulting random number.
Output
is also 2 lines, the 1th behavior 1 positive integers m, representing the number of random numbers that are not identical. The 2nd Act m A positive integer separated by a space, which is a different random number from small to large rows. Sample Input
20 40 32 67 40 20 89 300 400 15
Sample Output
8
15 20 32 40 67 89 300 400
HINT
Source
The fifth annual ACM Program Design Competition of Henan Polytechnic University
#include <stdio.h> #include <algorithm> using namespace std;
int a[105],b[105];
int main () {int i,n,k=0;
scanf ("%d", &n);
for (i=0;i<n;i++) scanf ("%d", &a[i]);
a[n]=10000;
Sort (a,a+n+1);
for (i=0;i<n;)
{if (a[i]==a[i+1]) i++;
else {b[k]=a[i];
i++;
k++;
} printf ("%d\n", K);
printf ("%d", b[0]);
for (i=1;i<k;i++) printf ("%d", b[i]);
return 0; }