寻找大富翁

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool comp(int a,int b)//从大到小
{
    return a>b;
}
int num[100010];
int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m),n+m)
    {
        memset(num,0,sizeof(num));
        for(int i=0;i<n;++i)
        {
            scanf("%d",&num[i]);
        }
        m=min(n,m);
        //sort(num,num+n,greater<int>());从大到小排序
        sort(num,num+n,comp);
        for(int i=0;i<m-1;++i)
        {
            printf("%d ",num[i]);
        }
        printf("%d\n",num[m-1]);
    }
    return 0;
}

你可能感兴趣的:(寻找大富翁)