- 奖学金
- 2013-08-06 08:17:38 @
哪位大侠帮忙看看下面的程序哪里有问题,这不就是个排序么。。。
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));
}
}
}
```