01:谁考了第k名 个人博客:doubleq.win

个人博客:doubleq.win

01:谁考了第k名

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名学生的学号和成绩。

输入
第一行有两个整数,分别是学生的人数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

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 using namespace std;
 5 int n,k;
 6 struct s
 7 {
 8     int xh;
 9     double cj;
10 }a[1001];
11 int comp(const s &a,const s &b)
12 {
13     return a.cj>b.cj;
14 }
15 int main()
16 {
17     cin>>n>>k;
18     for(int i=1;i<=n;i++)
19     {
20         cin>>a[i].xh;
21         cin>>a[i].cj;
22     }
23     sort(a+1,a+n+1,comp);
24     printf("%d ",a[k].xh);
25     printf("%g",a[k].cj);
26     return 0;
27 }

 

posted @ 2017-03-21 14:13  自为风月马前卒  阅读(552)  评论(0编辑  收藏  举报

Contact with me