当前位置:网站首页>Preliminary sequencing problem

Preliminary sequencing problem

2022-06-23 03:33:00 Dark horse breeze

Sorting is always on , All the time . In the algorithm, , Sort with count , Selection sort i, Bubble sort , Insertion sort , Quick sort and so on .

The following is a question using the sorting algorithm to illustrate the problem .

ELO Valley P1059 For example, the random number with a clear question .

#include<iosteam>
#include<algorithm>
using namespace std;
int const MAXN=1010;
int a[MAXN],ans[MAXN],n,cnt=0,tmp=-1;
int main(){
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(a[i]!=tmp)ans[cnt++]=a[i];
tmp=a[i];
}
cout<<cnt<<endl;
for(int i=0;i<cnt;i++)cout<<ans[i]<<' ';
return 0;
}

It's used here stl Algorithm .

原网站

版权声明
本文为[Dark horse breeze]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211734367191.html