题目描述 现有 N(N≤1000)N(N\le 1000)N(N≤1000) 名同学参加了期末考试,并且获得了每名同学的信息:姓名(不超过 8 个字符的字符串,没有空格)、语文、数学、英语成绩(均为不超过 150 的自然数)。总分最高的学生就是最厉害的,请输出最厉害的学生各项信息(姓名、各科成绩)。如果有多个总分相同的学生,输出靠前的那位。 输入格式 无 输出格式 无 输入输出样例 输入 #1 3 senpai 114 51 4 lxl 114 10 23 fafa 51 42 60 输出 #1 senpai 114 51 4
讯享网
讯享网import java.util.Scanner; public class P5740 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String[] s = new String[n]; int[][] score = new int[n][3]; for (int i = 0; i < n; i++) {
s[i] = sc.next(); for (int j = 0; j < 3; j++) {
score[i][j] = sc.nextInt(); } } int[] num = new int[n]; for (int i = 0; i < n; i++) {
num[i] = score[i][0] + score[i][1] + score[i][2]; } int maxValue = max(num); int index = indexOf(num, maxValue); System.out.print(s[index] + " "); System.out.print(score[index][0] + " " + score[index][1] + " " + score[index][2]); } public static int max(int[] array) {
int maxValue = array[0]; for (int i = 0; i < array.length; i++) {
if (array[i] > maxValue) {
maxValue = array[i]; } } return maxValue; } public static int indexOf(int[] array, int key) {
for (int i = 0; i < array.length; i++) {
if (array[i] == key) {
return i; } } return -1; } }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/52346.html