- /*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
- 时间:2013.03.20
- 作者:烟大洋仔
- 题目分析:
- 本题目由于在关闭系统以后再做的,不知道是不是可以AC,之前的几次提交的时候总是显示的是超时。。栈溢出这个不知道怎么解决???
- */
- #include <stdio.h>
- #include<iostream>
- #include<algorithm>
- #define x 1000000
- using namespace std;
- int main()
- {
- int n,m;
- int a[x];
- while(cin>>n>>m&&n>0&&m<1000000)
- {
- for(int i=0;i<n;i++)
- cin>>a[i];
- sort(a,a+n);
- for(int i=n-1;i>n-m-1;i--)
- cout<<a[i]<<" ";
- cout<<endl;
- }
- return 0;
- }
杭电ACM。。。sort
最新推荐文章于 2020-02-19 18:16:02 发布