SDNU random number 1209. Leilei

Description

Leilei would like to ask some of the 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, only a reservation, to remove the remaining the same number, corresponding to the number of different students learn different number. 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

Row 2 is input, the behavior of a first positive integer, denotes a random number generated by the number N

The second row has space-separated positive integer number N, the generated random number.

Output

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.

Sample Input

10
20 40 32 67 40 20 89 300 400 15

Sample Output

8
15 20 32 40 67 89 300 400

Source

#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long

int n;
map<int, int>mp;

int main()
{
    int x, flag = 0, sum = 0;
    scanf("%d", &n);
    for(int i = 0; i<n; i++)
    {
        scanf("%d", &x);
        if(!mp[x])sum++;
        mp[x] = 1;
    }
    cout<<sum<<endl;
    for(map<int, int>::iterator ii = mp.begin(); ii != mp.end(); ii++)
    {
        if(flag)cout<<" ";
        flag = 1;
        cout<<ii->first;
    }
    printf("\n");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/RootVount/p/10991364.html