sort
来源:互联网 发布:真实挂机赚钱软件 编辑:程序博客网 时间:2024/05/17 01:42
sort
Time Limit : 6000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 271 Accepted Submission(s) : 41
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 33 -35 92 213 -644
Sample Output
213 92 3
代码示例
#include<stdio.h>#include<algorithm>using namespace std;int a[1000000];/*第一次数组开在里边,因为数组太大,所以过不了*/ int main(){ int m,n,i,j; while(scanf("%d%d",&m,&n)!=EOF) { for(i=0;i<m;i++) scanf("%d",&a[i]); sort(a,a+m);/*暴力排序*/ for(j=m-1;j>m-n;j--)/*倒序输出*/ { printf("%d ",a[j]); } printf("%d\n",a[m-n]); } return 0;}
0 0
- sort
- Sort
- sort
- Sort
- sort
- Sort
- sort
- sort
- Sort
- Sort
- sort
- sort
- sort
- sort()
- sort
- sort
- sort
- sort
- MySQL之——服务器保持与MySQL的连接
- 【leetcode】123. Best Time to Buy and Sell Stock III
- HDOJ 2014 青年歌手大奖赛_评委会打分
- [Leetcode]-Best Time to Buy and Sell Stock II
- hdu 1814 Peaceful Commission (2-SAT)
- sort
- 人眼定位常用数据库
- STM8S---选项字节(Option Byte)写操作之IO复用
- MySQL5.5源码包和5.6源码包安装
- hdu 2020绝对值排序
- qsort 的注意事项
- 【整理】详解Python中re.sub
- 离散化/分箱/分组(Discretization / binning / Interactive grouping)
- HDOJ 2502 月之数