
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static class Student {
int studentno, grade;
public Student(int studentno, int grade) {
this.studentno = studentno;
this.grade = grade;
}
public void setStudentno(int studentno) {
this.studentno = studentno;
}
public int getStudentno() {
return studentno;
}
public void setGrade(int grade) {
this.grade = grade;
}
public int getGrade() {
return grade;
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
List<Student> students = new ArrayList<Student>();
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
//int b = in.nextInt();
//System.out.println(a + b);
for (int i = 0; i < a; i++) {
int studentno = in.nextInt();
int grade = in.nextInt();
students.add(new Student(studentno, grade));
}
students.sort((s1, s2)->s1.getGrade() - s2.getGrade()); //升序排序
Collections.sort(students, (s1,
s2)->s1.getGrade() - s2.getGrade()); //升序排序
students.sort(Comparator.comparing(Student::getGrade));//升序排序
Collections.sort(students, Comparator.comparing(Student::getGrade)); //升序排序
Collections.sort(students, new Comparator<Student>() {
public int compare(Student s1, Student s2) {
if(s1.grade==s2.grade){
return s1.getStudentno()-s2.getStudentno();//升序排序
}
return s1.getGrade()-s2.getGrade();//升序排序
}
});//升序排序
}
for (Student student : students) {
System.out.println(String.valueOf(student.studentno) + " " + String.valueOf(
student.grade));
}
}
}