Time Limit : 6000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 62 Accepted Submission(s) : 14
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给你n个整数,请按从大到小的顺序输出其中前m大的数。
Input
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
Output
对每组测试数据按从大到小的顺序输出前m大的数。
Sample Input
Sample Output
#include<stdio.h>
#include<algorithm>
using namespace std;
int x[1000010];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,m,i,j,k,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&x[i]);
sort(x,x+n,cmp);
for(i=0;i<m-1;i++)
printf("%d ",x[i]);
printf("%d\n",x[i]);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
sort
原文:http://blog.csdn.net/l15738519366/article/details/47004431