Popular driving range - obviously -P1059 sort of random numbers

Title Description
obviously want to invite some students in the school together to do a survey, in order to test the objectivity, his first with the computer-generated random integer (N≤100) between 1 and 1000 N number, for which duplicate numbers , but one, the rest the same number removed, different numbers corresponding to different students learn numbers. Then put these numbers in ascending order, to get the students to do research in accordance with good row order. Please help obviously complete "de-duplication" and "sort" work.

Input and output format
input format:

Row 2 is input, the behavior of a first positive integer representing the number of the generated random numbers: N, the second row has space-separated positive integer number N, the generated random number.

Output formats:

2 is an output line, line 1 is a positive integer M, represents the number of different random numbers. The second row are separated by spaces M a positive integer, from small to large are not sorted same random number.

Input Output Sample
Input Sample # 1:

10
20 40 32 67 40 20 89 300 400 15

Output Sample # 1:

. 8
15 32 40 20 is 67 89 300 400
----------------
idea: to do with bucket rows, STL

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>

using namespace std;
set <int>s;
int a[105];
int main(){
	
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		s.insert(a[i]);
	}
	cout<<s.size()<<endl;
	while(!s.empty())
	{
		 cout<<*s.begin()<<" ";           
        s.erase(s.begin()); 
	}
	
	return 0;
} 
Published 80 original articles · won praise 1 · views 1489

Guess you like

Origin blog.csdn.net/zqhf123/article/details/104339905