JAVA:
1036,一道水题
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeMap;
public class Main{
public static void main(String[] arg){
Scanner sc =new Scanner(System.in);
int n=Integer.valueOf(sc.nextLine().trim());
TreeMap<Integer,String[]> mapMale =new TreeMap<Integer,String[]>();
TreeMap<Integer,String[]> mapFemale =new TreeMap<Integer,String[]>();
Iterator<Integer> it ;
String[] line ;
int score;
for(int i=0;i<n;i++){
line =sc.nextLine().trim().split(" ");
score =Integer.valueOf(line[3]);
if("M".equals(line[1])){
mapMale.put(score, line);
}
else{
mapFemale.put(score, line);
}
}
int maleScore;
int femaleScore=0;
if(!mapMale.isEmpty() && !mapFemale.isEmpty()){
it =mapFemale.keySet().iterator();
while(it.hasNext()){
femaleScore = it.next();
}
System.out.println(mapFemale.get(femaleScore)[0]+" "+mapFemale.get(femaleScore)[2]);
it =mapMale.keySet().iterator();
maleScore = it.next();
System.out.println(mapMale.get(maleScore)[0]+" "+mapMale.get(maleScore)[2]);
System.out.println(femaleScore-maleScore);
}
else{
if(mapMale.isEmpty() && !mapFemale.isEmpty()){
it =mapFemale.keySet().iterator();
while(it.hasNext()){
femaleScore = it.next();
}
System.out.println(mapFemale.get(femaleScore)[0]+" "+mapFemale.get(femaleScore)[2]);
System.out.println("Absent");
System.out.println("NA");
}
if(!mapMale.isEmpty() && mapFemale.isEmpty()){
System.out.println("Absent");
it =mapMale.keySet().iterator();
maleScore = it.next();
System.out.println(mapMale.get(maleScore)[0]+" "+mapMale.get(maleScore)[2]);
System.out.println("NA");
}
}
}
}