HDU 1425 C++使用sort函数
来源:互联网 发布:淘宝标题在线优化 编辑:程序博客网 时间:2024/05/12 19:56
sort
Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45401 Accepted Submission(s): 13123
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 <iostream>#include <algorithm>#include <cstdio>using namespace std;int a[1000001];int cmp (int a,int b) { return a > b;}int main () { int num1,num2,num=1; while (scanf("%d%d",&num1,&num2)!=EOF) { for (int i=1; i<=num1; i++) scanf("%d",&a[i]); sort (a+1,a+num1+1,cmp); for(int i=1; i<=num2; i++) { if(i>1)printf(" "); printf("%d",a[i]); } printf("\n"); } return 0;}
看到的格式的另一种写法,其中使用了sort函数是c++库中的快速排序
0 0
- HDU 1425 C++使用sort函数
- C++sort函数使用总结
- c/c++ sort函数、qsort函数使用
- C/c++语言sort函数如何使用
- C语言sort函数如何使用
- C++sort 函数用法
- C++sort 函数用法
- C++sort 函数用法
- C++Sort函数用法
- C++sort函数
- C/C++中关于qsort和sort函数的使用
- C/C++sort函数用法
- sort函数的使用
- sort函数的使用
- sort函数使用
- sort()函数使用小结
- HDU 1425 sort(桶排序+哈希函数)
- HDU 1425 sort C语言实现快速排序
- jQuery lazyload 懒加载插件
- Android4.2.2源码编译-如何把第三方的动态库重新编译到Android系统的/system/lib目录
- 数据结构——选择排序、插入排序、冒泡排序、快速排序
- c++:定位new表达式
- 前端开发入门总结
- HDU 1425 C++使用sort函数
- Java NIO:浅析I/O模型
- ZKClient zookeeper 丢失事件 分析
- 目标检测:R-CNN
- 订单问题
- 魔术索引I
- 使用iptables防止SYN Flood攻击和CC攻击
- 注释转换
- 什么是进程死锁,如何解决?