Read the names, student numbers and grades of n students, respectively, and output the highest and lowest grade students ' names and school numbers.
input Format: each test input contains 1 test cases in the format
Line 1th: Positive integer n 2nd line: 1th Student's name School number results 3rd line: 2nd Student's name study number score ... Line n+1: Nth Student's name number score
Where both the name and the school number are not more than 10 characters of the string, the score is an integer between 0 and 100, which guarantees that no two students in a set of test cases have the same results.
output format: output 2 lines for each test case, the 1th line is the highest grade student's name and school number, the 2nd line is the lowest grade student's name and school number, there are 1 spaces between the strings.
Input Sample:
3Joe Math990112 89Mike CS991301 100Mary EE990830 95
Sample output:
Mike Cs991301joe Math990112
1 import Java.lang.reflect.Array;2 import java.util.ArrayList;3 import java.util.Arrays;4 import java.util.Collections;5 import java.util.List;6 import Java.util.Scanner;7 /**8 * Custom sorting using containers9 * @author ChinaTen * One */ A - Public classMain { - Public Static voidMain (string[] args) { theList<student> STDs =NewArraylist<student>(); -Scanner input =NewScanner (System.inch); - intnum =Integer.parseint (Input.nextline ()); - while(num>0){ +String str =input.nextline (); - //System.out.println (str); +string[] temp = str.split (" "); AStudent std =NewStudent (); atStd.name = temp[0]; -Std.stuid = temp[1]; -Std.score = Integer.parseint (temp[2]); - Stds.add (STD); -num--; - } in Collections.sort (STDs); -System. out. println (STDs.Get(0). name+" "+stds.Get(0). Stuid); toSystem. out. println (STDs.Get(Stds.size ()-1). name+" "+stds.Get(Stds.size ()-1). Stuid); + } - the } * classStudent Implements Comparable<student>{ $ String name;Panax Notoginseng String Stuid; - intscore; the @Override + PublicString toString () { A return "Student [Name="+ name +", stuid="+ Stuid +", score="+ score +"]"; the } + @Override - Public intcompareTo (Student o) { $ //TODO auto-generated Method Stub $ return-(score-o.score); - } - the}
PAT 1004. Score Ranking (JAVA)