描述
在一次考试中,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。学生总数不超过200名。若成绩相同,按照录入顺序排名。
格式
输入格式
其后有n行数据,每行包括一个学号(整数)和一个成绩(浮点数),中间用一个空格分隔。
输出格式
输出第k名学生的学号和成绩,中间用空格分隔。(注:请用%g输出成绩)
样例
输入样例
5 3
90788001 67.8
90788002 90.3
90788003 61
90788004 68.4
90788005 73.9
输出样例
90788004 68.4
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
//#define N 10001
int arr[501];
struct Student{
int id;
double score;
};
bool cmp2(Student a, Student b){
return a.score > b.score;
}
int main(){
Student s[501];
int n,k;
cin>>n>>k;
for(int i=0; i<n; ++i){
cin>>s[i].id>>s[i].score;
}
stable_sort(s, s+n, cmp2);
cout<<s[k-1].id<<" "<<s[k-1].score;
return 0;
}