简答题
偏难
#7445
谁考了第k名 在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。 时间限制:1000 内存限制:65536 输入…
谁考了第k名
在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。
时间限制:1000
内存限制:65536
输入
第一行有两个整数,分别是学生的人数n(1≤n≤100),和求第k名学生的k(1≤k≤n)。 其后有n行数据,每行包括一个学号(整数)和一个成绩(浮点数),中间用一个空格分隔。
输出
输出第k名学生的学号和成绩,中间用空格分隔。(注:请用%g输出成绩)
样例输入
5 3 90788001 67.8 90788002 90.3 90788003 61 90788004 68.4 90788005 73.9
样例输出
90788004 68.4
答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">//样例代码 结构体优先级排序
#include<iostream>
#include<algorithm>
using namespace std;
struct st{
int n;
double sore;
};
bool cmp1(st &a,st &b)
{
if(a.sore!=b.sore)
return a.sore>b.sore;
else return a.n<b.n;
}
int main()
{
int m,n;
cin>>n>>m;
st temp[102];
for(int i=0;i<n;i++)
{
cin>>temp[i].n>>temp[i].sore;
}
sort(temp,temp+n,cmp1);
cout<<temp[m-1].n<<" ";
printf("%g",temp[m-1].sore);
return 0;
}</pre><p><br/></p>
这道题暂未补解析。