一、题目链接
http://noi.openjudge.cn/ch0110/01/
二、解题思路
三、实施步骤
四、Java程序
import java.util.Arrays;
import java.util.Scanner;
class Student implements Comparable<Student> {
int id;
double score;
public Student(int id, double score) {
this.id = id;
this.score = score;
}
@Override
public int compareTo(Student o) {
if (o.score == this.score) {
return 0;
}
return o.score > this.score ? 1 : -1;
}
@Override
public String toString() {
return id + String.format(" %.1f", score);
}
}
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int k = input.nextInt();
Student[] students = new Student[n];
for (int i = 0; i < n; i++) {
int id = input.nextInt();
double score = input.nextDouble();
students[i] = new Student(id, score);
}
Arrays.sort(students);
System.out.print(students[k - 1].toString());
}
}