题目1431:Sort 题目11
来源:互联网 发布:水溶性润滑液 知乎 编辑:程序博客网 时间:2024/05/19 12:18
给你n个整数,请按从大到小的顺序输出其中前m大的数。
没有对排序算法的要求,因此直接用sort即可
题目描述:
- 输入:
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
- 输出:
对每组测试数据按从大到小的顺序输出前m大的数。
- 样例输入:
5 33 -35 92 213 -644
- 样例输出:
213 92 3
#include <stdio.h>#include <iostream>#include <string>#include <string.h>#include <algorithm>using namespace std;int main(){int n,m;while(scanf("%d %d",&n,&m)!=EOF){int *a=new int[n];int i=0;for (i=0;i<n;i++){scanf("%d",&a[i]);}sort(a,a+n);for (i=n-1;i>n-m;i--){printf("%d ",a[i]);}printf("%d\n",a[n-m]);} return 0;}
0 0
- 题目1431:Sort 题目11
- 11-题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目11:Sort
- 九度题目1431:Sort
- 九度 题目1431:Sort
- 九度题目1431:Sort
- 【九度】题目1431:Sort
- 题目1431:Sort(哈希算法)
- 九度-简单题 题目1431:Sort
- LeetCode题目4:Sort List
- LeetCode之Sort题目汇总
- LeetCode算法题目:Sort List
- LeetCode算法题目:Sort Colors
- HDOJ 4417 Super Mario
- Tian Ji -- The Horse Racing(贪心)
- C#多线程学习(1-6)
- 动画客户端的分辨率设计
- java学习记录
- 题目1431:Sort 题目11
- 从表到里学习JVM实现
- VS2013 c++ 修改默认活动解决方案平台
- 克服程序拖延症
- Linux文件系统 硬链接与符号链接
- ISODATA源代码
- 数学之美--64汉诺塔之传说
- 你应该远离的6个Java特性
- 针对自己的情况,NVIDIA驱动的使用