题解 | 最厉害的学生

最厉害的学生

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);
    }
}

全部评论
点赞 回复 分享
发布于 01-26 15:42 山东

相关推荐

烤点老白薯:感觉这女生 有上位者的甲方心态 不适合处对象 也不清楚自己的竞争力 整得他有多懂似的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务