H.E.L.P

哪位大侠帮忙看看下面的程序哪里有问题,这不就是个排序么。。。

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

static class Score{
int idx;
int c;
int m;
int e;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
List<Score> list = new ArrayList<Score>();
int n = in.nextInt();
for(int i = 1; i <= n; i++) {
Score s = new Score();
s.idx = i;
s.c = in.nextInt();
s.m = in.nextInt();
s.e = in.nextInt();
list.add(s);
}

Collections.sort(list, new Comparator<Score>(){
@Override
public int compare(Score o1, Score o2) {
int t1 = o1.c + o1.m + o1.e;
int t2 = o2.c + o2.m + o2.e;
if(t1 != t2) {
return t1 > t2 ? -1 : 1;
}
if(o1.c != o2.c) {
return o1.c > o2.c ? -1 : 1;
}
return o1.idx < o2.idx ? -1 : 1;

}});

list = list.subList(0, 5);
for(Score s : list) {
System.out.println(""+s.idx +" "+ (s.c+s.e+s.m));
}
}
}
```

0 条评论

目前还没有评论...

信息

ID
1398
难度
4
分类
其他 | 排序 点击显示
标签
递交数
6447
已通过
2665
通过率
41%
被复制
22
上传者