3012 谁考了第k名 单条件

 

#include<bits/stdc++.h>
#define f(i,s,e) for(int i = s; i <= e; i++)
#define ll long long
using namespace std;
const int N = 1e3+10,inf = 0x3f3f3f3f;
struct node{
    string xh; //学号
    double cj; //成绩 
};
node a[N]; //结构体数组
bool cmp(node a,node b)
{
    return a.cj > b.cj; //成绩大的优先,所以使用 > 
} 
int main()
{
    int n,k; cin >> n >> k;
    f(i,1,n) cin >> a[i].xh >> a[i].cj; //先输入学号xh,在输入成绩cj
    
    sort(a + 1, a + 1 + n, cmp); //对下标1到n进行排序
     
    cout << a[k].xh << " " << a[k].cj << endl; //输出第k名学生的学号和成绩 
    return 0;
}

 

posted @ 2024-06-28 17:27  CRt0729  阅读(9)  评论(0编辑  收藏  举报