码迷,mamicode.com
首页 > 其他好文 > 详细

sort

时间:2015-07-22 19:06:00      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

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;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

sort

标签:

原文地址:http://blog.csdn.net/l15738519366/article/details/47004431

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!