原题
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1§ionid=3&problemid=5
源码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
if(n == 0) {
return;
}
int m = in.nextInt(), g = in.nextInt(), i;
int[] scores = new int[m];
String a = in.nextLine();
String[] strings = in.nextLine().split("\\s");
for(i = 0;i < m;i++){
scores[i] = Integer.parseInt(strings[i]);
}
Set<Person> qualified = new TreeSet<>();
for(i = 0;i < n; i++){
String[] temp = in.nextLine().split("\\s");
int sum = 0;
for(int j = 0;j < Integer.parseInt(temp[1]);j++){
sum += scores[Integer.parseInt(temp[j + 2]) - 1];
}
if(sum >= g){
Person p = new Person();
p.no = temp[0];
p.score = sum;
qualified.add(p);
}
}
Iterator it = qualified.iterator();
System.out.println(qualified.size());
while (it.hasNext()){
System.out.println(it.next().toString());
}
}
}
static class Person implements Comparable<Person> {
String no;
int score;
@Override
public int compareTo(Person o) {
int result;
if(this.score > o.score)
result = -1;
else if(this.score < o.score)
result = 1;
else result = 0;
if (result == 0){
result = this.no.compareTo(o.no);
}
return result;
}
@Override
public String toString() {
return no + " " + score;
}
}
}