在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。
第一行有两个整数,分别是学生的人数n(1≤n≤100)n(1≤n≤100),和求第k名学生的k(1≤k≤n)k(1≤k≤n)。
其后有nn行数据,每行包括一个学号(整数)和一个成绩(浮点数),中间用一个空格分隔。
其实这道题就是复习一下,排序输出。
```Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
int index =sc.nextInt();
int [] number =new int[n];
double [] score =new double[n];
for (int i = 0; i < number.length; i++) {
number[i] =sc.nextInt();
score[i] =sc.nextDouble();
}
for (int i = 0; i < score.length-1; i++) {
for (int j = 0; j < score.length - 1 - i; j++) {
if (score[j]>score[j+1]){
double ts =score[j];
score[j] = score[j + 1];
score[j + 1] = ts;
int t =number[j];
number[j] = number[j + 1];
number[j + 1] = t;
}
}
}
System.out.println(number[index-1]+" "+score[index-1]);
}
}