1. 程式人生 > >PAT-1004 成績排名 (20 分)

PAT-1004 成績排名 (20 分)

1004 成績排名 (20 分)

讀入 n(>0)名學生的姓名、學號、成績,分別輸出成績最高和成績最低學生的姓名和學號。
輸入格式:
每個測試輸入包含 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

public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String string = reader.readLine();
        int n=Integer.parseInt(string);
        String max="";
        String min="";
        int maxnum=-1;
        int
minnum=101; for (int i = 0; i <n; i++) { string=reader.readLine(); String[]strings=string.split(" "); int m1=Integer.parseInt(strings[2]); if(m1<minnum){ minnum=m1; min=strings[0]+" "+strings[1]; }
if(m1>maxnum){ maxnum=m1; max=strings[0]+" "+strings[1]; } } System.out.println(max); System.out.println(min); }