和网上大多版本一样 都是16分,代码AC不了,就想说java对运行时间太不友好了。
但用的Treeset集合 和 Comparator排序,这样本以为会快一些,但没用。但是代码可能简单一些。
import java.util.Comparator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
int N, L, H;
Scanner in = new Scanner(System.in);
N = in.nextInt(); //总人数
L = in.nextInt();// 最低录取线
H = in.nextInt();// 优先录取线
in.nextLine();
Set<Stu> ts = new TreeSet<Stu>(new Comparator<Stu>() {
@Override
public int compare(Stu o1, Stu o2) {
int num1 = o2.gra - o1.gra;
int num2 = num1 == 0 ? (o2.sum - o1.sum) : num1;
int num3 = num2 == 0 ? (o2.grade1 - o1.grade1) : num2;
int num4 = num3 == 0 ? (o1.getId().compareTo(o2.getId())) : num3;
return num4;
}
});
for (int i = 0; i < N; i++) {
String s;
int de, cai, sum;
s = in.next();
de = in.nextInt();
cai = in.nextInt();
sum = de + cai;
if (de >= L && cai >= L) {
if (de >= H && cai >= H) {
Stu p = new Stu(s, de, cai, 5, sum);
ts.add(p);
} else if (de >= H && cai < H) {
Stu p = new Stu(s, de, cai, 4, sum);
ts.add(p);
} else if (de < H && cai < H && de >= cai) {
Stu p = new Stu(s, de, cai, 3, sum);
ts.add(p);
} else {
Stu p = new Stu(s, de, cai, 2, sum);
ts.add(p);
}
}
}
System.out.println(ts.size());
for (Stu p : ts) {
System.out.println(p.id + " " + p.grade1 + " " + p.grade2);
}
}
}
class Stu {
String id;
int grade1, grade2, sum;
int gra;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Stu(String id, int grade1, int grade2, int gra, int sum) {
this.id = id;
this.grade1 = grade1;
this.grade2 = grade2;
this.gra = gra;
this.sum = grade1 + grade2;
}
}