hdu 1425 整理下水題 排序

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
Hint
Hint
請用VC/VC++提交
 

#include<stdio.h>
#include<algorithm>
using namespace std;
int a[10000000];

int main()
{
    int n,i,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        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",a[n-m]);
        printf("\n");
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章