#include<iostream>
#include<cctype>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int n;
vector<int> kv;
void mysort(){
for(int i=1; i<kv.size(); i++){
int j = i-1;
int temp = kv[i];
while(j>=0 && temp<kv[j]){
kv[j+1] = kv[j];
j--;
}
if(j<0){
kv[0] = temp;
}else{
kv[j+1] = temp;
}
}
}
int main()
{
cin>>n;
for(int i=0; i<n; i++){
int x;
cin>>x;
if(find(kv.begin(), kv.end(), x)==kv.end()){
kv.push_back(x);
}
}
cout<<kv.size()<<endl;
mysort();
for(int i=0; i<kv.size(); i++){
cout<<kv[i]<<' ';
}
cout<<endl;
return 0;
}
#include<iostream>
#include<cctype>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int n;
vector<int> kv;
int Find(int left, int right, int x){
int mid = (left+right)/2;
while(left<=right && kv[mid]!=x){
if(kv[mid]>x){
right = mid-1;
}else{
left = mid+1;
}
mid = (left+right)/2;
}
if(left>right){
return left;
}else{
return mid;
}
}
void mysort(){
for(int i=1; i<kv.size(); i++){
int loc = Find(0, i-1, kv[i]);
int temp = kv[i];
for(int j=i; j>loc; j--){
kv[j] = kv[j-1];
}
kv[loc] = temp;
}
}
int main()
{
cin>>n;
for(int i=0; i<n; i++){
int x;
cin>>x;
if(find(kv.begin(), kv.end(), x)==kv.end()){
kv.push_back(x);
}
}
cout<<kv.size()<<endl;
mysort();
for(int i=0; i<kv.size(); i++){
cout<<kv[i]<<' ';
}
cout<<endl;
return 0;
}
|