25 5科总分

25 5科总分

作者: 江宝钏时间限制: 1S章节: 二维数组

问题描述 :

输入10个学生的学号和5门课程的成绩,统计输出5门课总分最高和最低的学生的学号和他们的总分。

输入说明 :

每行6个整数,共10行。

其中,每行第一个整数表示学生的学号,剩下的5个数表示他5门课程的成绩。

输出说明 :

两行,每行两个整数。

其中第一行为总分最高的学生的学号,和他的总分,用空格隔开。

第二行为总分最低的学生的学号,和他的总分,用空格隔开。

输入范例 :

99211201 1 2 3 4 5
99211207 2 2 3 4 5
99211217 3 2 3 4 5
99211227 4 2 3 4 5
99211231 5 2 3 4 5
99211232 6 2 3 4 5
99211233 7 2 3 4 5
99211235 8 2 3 4 5
99211236 9 2 3 4 5
99211237 10 2 3 4 5
输出范例 :

99211237 24
99211201 15

import java.util.Scanner;

public class test_25 {
    /**
     * 25 5科总分
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum;
        String s;
        String[] split;
        int[][] student = new int[10][7];
        for (int i = 0; i < 10; i++) {
            s = sc.nextLine();
            split = s.trim().replaceAll("\t"," ").split(" ");
            sum=0;
            for (int j = 0; j < 6; j++) {
                student[i][j]=Integer.valueOf(split[j]);
                if(j>=1){
                    sum+=student[i][j];
                }
            }
            student[i][6]=sum;
        }
        int max=student[0][6],maxStudent=0,min=student[0][6],minStudent=0;
        for (int i = 1; i < 10; i++) {
            if(student[i][6]>max){
                max=student[i][6];
                maxStudent=i;
            }
            if(student[i][6]<min){
                min=student[i][6];
                minStudent=i;
            }
        }
        System.out.println(String.valueOf(student[maxStudent][0])+" "+max);
        System.out.println(String.valueOf(student[minStudent][0])+" "+min);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值