Random Number of NYOJ-C small plus

Source: Internet
Author: User
C Small plus random number time limit: 3000 MS | memory limit: 65535 kb difficulty: 1
Description
The "C Xiaojia" Team of the ACM team wants to invite some students to conduct a questionnaire survey in the school to ensure the objectivity of the experiment, he first generates n random integers (0 <n ≤ 1000) between 1 and 100 on the computer. For repeated numbers, only one is retained and the remaining identical numbers are removed, different numbers correspond to different student IDs. Then sort these numbers from small to large and sort them to the students for investigation. Please help c Xiaojia complete "de-duplication" and "sorting.
Input
The number of groups of test data in the first line is represented by an integer T (1 <t <10,
Each group of test data includes two rows,
1st act 1 positive integer, indicating the number of random numbers generated: n (0 <n ≤ 100)
The first row contains n positive integers separated by spaces, which are the random numbers generated.
(The random number is given by the question and does not need to be generated by acmer)
Output
The output is also two rows. 1st acts as a positive integer m, indicating the number of random numbers that are not the same.
2nd act M positive integers separated by spaces. They are random numbers in ascending order.
Sample Input
11020 40 32 67 40 20 89 300 400 15
Sample output
815 20 32 40 67 89 300 400
Code:
#include<stdio.h>#include<algorithm>using namespace std;int main(){int t,a[110];scanf("%d",&t);while(t--){int n,i,k;scanf("%d",&n);for(i=0;i<n;++i)scanf("%d",&a[i]);sort(a,a+n);k=1;for(i=1;i<n;++i){if(a[i]!=a[i-1])k++;}printf("%d\n",k);printf("%d",a[0]);for(i=1;i<n;++i){if(a[i]!=a[i-1])printf(" %d",a[i]);}printf("\n");}return 0;}

Random Number of NYOJ-C small plus

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.