hdu3785
尋找大富翁
Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2459????Accepted Submission(s): 1162
?
Input 輸入包含多組測試用例.每個用例首先包含2個整數n(0<n<=100000)和m(0<m<=10),其中: n為鎮上的人數,m為需要找出的大富翁數, 接下來一行輸入鎮上n個人的財富值.
n和m同時為0時表示輸入結束.
?
Output 請輸出烏鎮前m個大富翁的財產數,財產多的排前面,如果大富翁不足m個,則全部輸出,每組輸出占一行.?
Sample Input 3 1 2 5 -1 5 3 1 2 3 4 5 0 0?
Sample Output 5 5 4 3?
Source 浙大計算機研究生復試上機考試-2009年 #include<iostream>#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
??? int n,m,i,j,a[100010],t;
??? while(~scanf("%d%d",&n,&m)&&(n||m))
??? {
??????? for(i=0; i<n; i++)
??????????? scanf("%d",&a[i]);
??????? sort(a,a+n);
??????? for(i=n-1; i>n-1-m; i--)
??????????? if(i==n-1)
??????????????? printf("%d",a[i]);
??????????? else
??????????????? printf(" %d",a[i]);
??????? printf("\n");
??? }
}
轉載于:https://www.cnblogs.com/lxm940130740/p/3333794.html
總結
                            
                        - 上一篇: websocket vs keep-li
 - 下一篇: poj 1966(顶点连通度)