20170819_取出重复元素使其唯一并排序
//测试程序:
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
#include<cstdlib>
#include<ctime>
using namespace std;
class Solution
{
public:
void deleteCopyAndSort(int n)
{
vector<int> num(n,0);
for(int i=0; i<n; ++i)
cin>>num[i];
int sz1=num.size();
cout<<sz1<<endl;
for(int i=0; i<=sz1-2; ++i)
cout<<num[i]<<" ";
cout<<num[sz1-1]<<endl;
sort(num.begin(),num.end()); //排序
num.erase(unique(num.begin(),num.end()),num.end()); //去重
int sz2=num.size();
cout<<sz2<<endl;
for(int i=0; i<=sz2-2; ++i)
cout<<num[i]<<" ";
cout<<num[sz2-1]<<endl;
}
};
int main(void)
{
int n=0;
cin>>n;
class Solution object;
object.deleteCopyAndSort(n);
system("pause");
return 0;
}