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