解题思路:
注意事项: 只要注意小于5就可以了。
参考代码:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class d {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n=scanner.nextInt();
int a,b,c;
node[] ch=new node[n];
for (int i=0;i<n;i++){
a=scanner.nextInt();
b=scanner.nextInt();
c=scanner.nextInt();
ch[i]=new node(a,i+1,a+b+c);
}
Arrays.sort(ch, new Comparator<node>() {
@Override
public int compare(node o1, node o2) {
if (o1.sum==o2.sum){
if (o1.chinese==o2.chinese){
return o1.id-o2.id;
}
return o2.chinese-o1.chinese;
}
return o2.sum-o1.sum;
}
});
if (n>5){
for (int i=0;i<5;i++){
System.out.println(ch[i].id+" "+ch[i].sum);
}
}else {
for (int i=0;i<n;i++){
System.out.println(ch[i].id+" "+ch[i].sum);
}
}
}
}
class node{
int chinese;
int id;
int sum;
public node(int chinese, int id,int sum) {
this.chinese = chinese;
this.id = id;
this.sum=sum;
}
}
0.0分
1 人评分