题解 | 最厉害的学生
最厉害的学生
https://www.nowcoder.com/practice/b6e7a9ca04d8418b805b3b4b7d25b4d4
import java.util.Scanner;
class Student{
String name;
int c1,c2,c3;
public Student(String name,int c1,int c2,int c3){
this.name = name;
this.c1 = c1;
this.c2 = c2;
this.c3 = c3;
}
public int getTotal(){
return c1+c2+c3;
}
}
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Student Best = null;
for(int i = 0;i<n;i++){
String name = in.next();
int c1 = in.nextInt();
int c2 = in.nextInt();
int c3 = in.nextInt();
Student cur = new Student(name,c1,c2,c3);
if(Best==null||Best.getTotal()<cur.getTotal()){
Best = cur;
}
}
System.out.print(Best.name+" "+Best.c1+" "+Best.c2+" "+Best.c3);
}
}
