Random Numbers get rid of repetition and sorting

  • 2020-04-01 21:31:49
  • OfStack


#include <iostream> 
#include <stdio.h> 
#include <set> 
using namespace std; 

int main() 
{ 
    int n,a,i; 
    set<int>m; 
    while(scanf("%d",&n)!=EOF) 
    { 
        for(i=0;i<n;i++) 
        { 
            scanf("%d",&a); 
            m.insert(a); 
        } 
        set<int>::iterator it; 
        printf("%dn",m.size()); 
        for(it=m.begin();it!=m.end();it++) 
        { 
            if(it==m.begin()) 
            printf("%d",*it); 
            else
            printf(" %d",*it); 
        } 
        printf("n"); 
        m.clear(); 
    } 
    return 0; 
} 


Related articles: