一枚渣子


私信TA

用户名:uq_44501180482

访问量:14566

签 名:

笨蛋

等  级
排  名 24
经  验 15947
参赛次数 1
文章发表 238
年  龄 0
在职情况 在职
学  校 河南科技大学
专  业

  自我简介:

渣子

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class Stus{
	int Sno;
	int Chinese;
	int Score;
	public Stus(int sno,int chinese,int score){
		Sno=sno;
		Chinese=chinese;
		Score=score;
	}
}
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		Stus[]stu=new Stus[n];
		for (int i = 0; i < n; i++) {
			int Chinese=sc.nextInt();
			int Math=sc.nextInt();
			int English=sc.nextInt();
			stu[i]=new Stus(i+1,Chinese,Chinese+Math+English);
		 }
	   Arrays.sort(stu,new Comparator<Stus>(){
		@Override
		public int compare(Stus s1, Stus s2) {
			if(s2.Score==s1.Score&&s2.Chinese==s1.Chinese) return s1.Sno-s2.Sno;
			else if(s2.Score==s1.Score) return s2.Chinese-s1.Chinese;
			return s2.Score-s1.Score;
		   }
	     });
	   try 
	   {
		   for (int i = 0; i < 5; i++) 
				System.out.println(stu[i].Sno+" "+stu[i].Score );
	    } 
	   catch (Exception e) {
     }
  }
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区