44:班级排名
描述
信息科学技术学院年终评定讲学金,需要对整个年级的学生按照平均分数进行排名;要求:根据输入的学号和平均成绩,按照平均成绩降序输出学号;如果平均成绩相同,按照输入的顺序输出。
输入
第一行为N,表示输入N位学生的信息,接着的N行输入学生信息,1<=N<=500;学生信息的格式为:学号 平均成绩;学号的长度小于10,平均成绩在1-100之间.
输出
按照平均成绩降序输出学号,如果平均成绩相同,按照输入顺序输出
样例输入
5
10948001 80
10948004 90
10948101 95
10948102 80
10948209 90
样例输出
10948101
10948004
10948209
10948001
10948102
代码
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main
{
static class student
{
public int id;
public int fs;
public String xh;
student(int id, int fs, String xh)
{
this.id = id;
this.fs = fs;
this.xh = xh;
}
public void display()
{System.out.println(this.xh);}
}
static class fssort implements Comparator<student>
{
public int compare(student o1, student o2)
{
if(o1.fs == o2.fs)
return o1.id - o2.id;
return o2.fs - o1.fs;
}
}
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
student[] people = new student[n];
for(int i = 0; i < n; i++)
{
String s = cin.next();
int x = cin.nextInt();
people[i] = new student(i,x,s);
}
Arrays.sort(people, new fssort());
for(int i = 0; i < n; i++)
people[i].display();
}
}