题目1034:寻找大富翁
参考代码:
</pre><p><pre name="code" class="java">import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;
public class Main {
//private static final Integer[] Integer = null;
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
if(m==0 && n==0) break;
//Person[] persons = new Person[n];
Integer[] persons = new Integer[n];
for(int i=0;i<n;i++)
{
//persons[i]=new Person(sc.nextInt());
persons[i] = sc.nextInt();
}
//sortPerson(persons);
Arrays.sort(persons,Collections.reverseOrder());
for(int i=0;i<Math.min(persons.length, m);i++){
System.out.print(persons[i]);
if(i!=Math.min(persons.length, m)-1) System.out.print(" ");
}
System.out.println();
}
}
}