-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e5255d
commit 8bee08f
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import java.util.*; | ||
|
||
class Student{ | ||
private int id; | ||
private String fname; | ||
private double cgpa; | ||
public Student(int id, String fname, 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; | ||
} | ||
} | ||
|
||
class SortResult implements Comparator<Student>{ | ||
public int compare(Student a, Student b){ | ||
if(a.getCgpa() == b.getCgpa()){ | ||
if(a.getFname().equals(b.getFname())) | ||
return (a.getId() < b.getId() ? 1 : -1); | ||
else | ||
return a.getFname().compareTo(b.getFname()); | ||
} | ||
else{ | ||
return (a.getCgpa() < b.getCgpa() ? 1 : -1); | ||
} | ||
} | ||
} | ||
|
||
public class Solution { | ||
public static void main(String[] args){ | ||
Scanner in = new Scanner(System.in); | ||
int testCases = Integer.parseInt(in.nextLine()); | ||
|
||
List<Student> studentList = new ArrayList<Student>(); | ||
while(testCases > 0){ | ||
int id = in.nextInt(); | ||
String fname = in.next(); | ||
double cgpa = in.nextDouble(); | ||
|
||
Student st = new Student(id, fname, cgpa); | ||
studentList.add(st); | ||
|
||
testCases--; | ||
} | ||
SortResult sorter = new SortResult(); | ||
Collections.sort(studentList, sorter); | ||
for(Student st: studentList){ | ||
System.out.println(st.getFname()); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|