HH's random number (hpu1122)

Source: Internet
Author: User
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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.