您的位置:首页 > 其它

sort

2015-07-22 15:41 399 查看

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

5 3
3 -35 92 213 -644


Sample Output

213 92 3


#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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: