思路:使用二维数组把数据存起来,同时把每个学生的成绩记录在成绩数组中。对成绩数组进行排序,成绩数组的最后一个元素是最大的,最小的是第一个元素。把成绩数组的成绩与成绩单数组的成绩对比,就可找出最大最小的学生成绩。
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[][] cjd = new String[n][3];
int[] score = new int[n];
for(int i =0; i<n; i++){
for(int j=0; j<3; j++){
cjd[i][j] = sc.next();
}
score[i] = Integer.parseInt(cjd[i][2]);
}
Arrays.sort(score);
for(int i=n-1; i>=0; i--){
if(Integer.parseInt(cjd[i][2]) == score[n-1]){
System.out.println(cjd[i][0] + " "+ cjd[i][1]);
}
if(Integer.parseInt(cjd[i][2]) == score[0]){
System.out.println(cjd[i][0] + " "+ cjd[i][1]);
}
}
}
}

京公网安备 11010502036488号