题目描述
JAVA版本
样例
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String maleName = "", maleId = "";
int maleScore = 0;
String femaleName = "", femaleId = "";
int femaleScore = 0;
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
for (int i = 0; i < m; i++) {
String name = scanner.next();
String sex = scanner.next();
String id = scanner.next();
int score = scanner.nextInt();
if (sex.equals("F")) {
if (femaleName.isEmpty()|| femaleScore < score) {
femaleName = name;
femaleScore = score;
femaleId = id;
}
}
} else {
if (maleName.isEmpty()||maleScore > score) {
maleName = name;
maleScore = score;
maleId = id;
}
}
}
scanner.close();
int flag = 0;
if (!femaleName.isEmpty()) {
System.out.println(femaleName + " " + femaleId);
} else {
System.out.println("Absent");
flag++;
}
if (!maleName.isEmpty()) {
System.out.println(maleName + " " + maleId);
} else {
System.out.println("Absent");
flag++;
}
if (flag > 0) {
System.out.println("NA");
} else {
System.out.println(femaleScore - maleScore);
}
}
}