class students
{
int Score,id;
}
class mycmp implements Comparator<students>
{
@Override
public int compare(students A, students B) {
// TODO Auto-generated method stub
if(A.Score == B.Score)
{
return 0; //返回0代表不交换顺序。如果直接返回0,会原封不动输出。
}else
return A.Score > B.Score ? -1 : 1; //降序排列,如果返回-1,代表不交换顺序
}
}
public class 成绩排序 {
static int n;
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
students stu[] = new students[n];
for(int i =0 ;i<n;i++)
{
stu[i] = new students();
stu[i].Score = sc.nextInt();
stu[i].id = i+1;
}
Arrays.sort(stu,0,n,new mycmp());
for(int i = 0; i<n;i++)
{
if(i!=n-1)
{
System.out.print(stu[i].id + " ");
}else
System.out.print(stu[i].id);
}
}
}
计蒜客 成绩排序(“结构体”)
最新推荐文章于 2022-03-31 09:38:49 发布