码农谷 输出成绩最高和成绩最低学生姓名和学号

读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

输入格式:每个测试输入包含1个测试用例,格式为

  第1行:正整数n

  第2行:第1个学生的姓名 学号 成绩

  第3行:第2个学生的姓名 学号 成绩

  ... ... ...

  第n+1行:第n个学生的姓名 学号 成绩

其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

输出格式:对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最低学生的姓名和学号,字符串间有1空格。

样例

输入:

3

Joe Math990112 89

Mike CS991301 100

Mary EE990830 95

输出:

Mike CS991301

Joe Math990112 
=====================================
第一次code:
 1 import java.util.Scanner;
 2 /**
 3 *  时间:2016.7.16
 4 */
 5 public class Main
 6 {
 7     public static void main(String[] args)   
 8     {
 9         Scanner input = new Scanner(System.in);
10         int i,j;
11         int q=0;
12         int p=0;
13         int n = input.nextInt();
14         String [][]arrey = new String[n][3];
15         int[]m = new int[n];
16         for(i=0;i<n;i++)
17         {
18             for(j=0;j<2;j++)
19             {
20                 if(input.next().length()<11)
21                 {
22                     arrey[i][j]=input.next();
23                 }
24             }
25             if(0<=input.nextInt() && input.nextInt()<=100)
26             {
27                 arrey[i][2]=String.valueOf(input.nextInt());
28             }
29         }
30         for(i=0;i<n;i++)
31         {
32             m[i]=Integer.valueOf(arrey[i][2]);
33         }
34         int max = m[0];
35         int min = m[0];
36         for(i=0;i<m.length;i++)
37         {
38             if(max<m[i])
39             {
40                 max=m[i];
41                 q=i;
42             }
43             if(min>m[i])
44             {
45                 min=m[i];
46                 p=i;
47             }
48         }
49         System.out.println(arrey[q][0]+" "+arrey[q][1]+"
");
50         System.out.println(arrey[p][0]+" "+arrey[p][1]);
51     }
52 }
原文地址:https://www.cnblogs.com/niithub/p/5807091.html