解题思路: 构造对象,重写比较方法,排序后输出
注意事项: 注意输出格式,我实在是没搞懂题目的%g,AC过了说明不需要按%g格式输出,直接输出就行
参考代码:
import java.util.Arrays; import java.util.Scanner; /** * 2021年2月16日 下午8:32:46 * @author praguetramp */ public class Main implements Comparable<Object> { String id; float score; Main(String id,float score){ this.id=id;this.score=score; } @Override public int compareTo(Object o) { int flag=-1; Main o1 = (Main)o; if(this.score>o1.score) flag=1; return flag; } public static void main(String []args) { Scanner in =new Scanner(System.in); int n=in.nextInt(),k=in.nextInt(); Main arr[] = new Main[n]; for(int i=0;i<n;i++) arr[i]=new Main(in.next(), in.nextFloat()); Arrays.sort(arr); System.out.printf("%s ",arr[n-k].id); System.out.println(arr[n-k].score); in.close(); } }
0.0分
7 人评分
【偶数求和】 (C语言代码)浏览:639 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:636 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:531 |
幸运数 (C++代码)浏览:1258 |
A+B for Input-Output Practice (III) (C语言代码)浏览:564 |
筛排处理 (C语言代码)浏览:782 |
小O的乘积 (C++代码)浏览:518 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:417 |
C二级辅导-计负均正 (C语言代码)浏览:634 |
1415题求解浏览:606 |