使用sort非降序排序
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int rich[100001];
bool comp(const int x,const int y)
{
return x>y;
}
int main()
{
int n,m,i,j;
while(~scanf("%d %d",&n,&m)!=EOF&&(n!=0||m!=0))
{
for(i=0;i<n;i++)
scanf("%d",&rich[i]);
sort(rich,rich+n,comp);
printf("%d",rich[0]);
if(m>n)
for(j=1;j<n;j++)
printf(" %d",rich[j]);
else
for(j=1;j<m;j++)
printf(" %d",rich[j]);
printf("\n");
}
return 0;
}