解题思路: 构造对象,重写比较方法,排序后输出
注意事项: 注意输出格式,我实在是没搞懂题目的%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 人评分
Hello, world! (C语言代码)浏览:1196 |
C语言训练-角谷猜想 (C语言代码)浏览:1705 |
大小写转换 (C语言代码)浏览:839 |
简单的a+b (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题6.8 (C++代码)浏览:575 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:853 |
字符逆序 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:560 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:486 |
交换Easy (C语言代码)浏览:759 |