5
33 Rumpa 3.68
85 Ashis 3.85
56 Samiha 3.75
19 Samara 3.75
22 Fahim 3.76

Ashis
Fahim
Samara
Samiha
Rumpa

#### 參考答案

```import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {

public static void main(final String[] args) {
final Scanner in = new Scanner(System.in);
int testCases = Integer.parseInt(in.nextLine());

final List<Student> studentList = new ArrayList<>();
while (testCases > 0) {
final int id = in.nextInt();
final String fname = in.next();
final double cgpa = in.nextDouble();

final Student st = new Student(id, fname, cgpa);

testCases--;
}
studentList.sort((a, b) -> {
final double cgpaA = a.getCgpa(), cgpaB = b.getCgpa();
if (cgpaA > cgpaB) {
return -1;
} else if (cgpaA < cgpaB) {
return 1;
}
final int nameCompare = a.getFname().compareTo(b.getFname());

if (nameCompare < 0) {
return -1;
} else if (nameCompare > 0) {
return 1;
}

return a.getId() - b.getId();
});
for (final Student st : studentList) {
System.out.println(st.getFname());
}
}
}

class Student {

private int id;
private String fname;
private double cgpa;

public Student(final int id, final String fname, final double cgpa) {
super();
this.id = id;
this.fname = fname;
this.cgpa = cgpa;
}

public int getId() {
return id;
}

public String getFname() {
return fname;
}

public double getCgpa() {
return cgpa;
}
}```