1941 最高分数的学生姓名 结构体例题

 

#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 name; //姓名 
    int score; //成绩 
};
node a[N]; //结构体数组 
int n;
bool cmp(node a,node b)
{
    return a.score > b.score; //成绩高的优先 
}
int main()
{
    cin >> n;
    f(i,1,n) cin >> a[i].score >> a[i].name; //输入成绩和姓名 
    sort(a + 1, a + 1 + n, cmp); //对下标1到n进行排序 
    cout << a[1].name; //输出第1名的姓名 
    return 0;
}

 

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