这一题总算是把C++的重载活学活用了一回,节省了很多脑细胞。

#include<bits/stdc++.h>
using namespace std;

struct student{
    string name;
    string code;
    int score;
    //operator <
    bool operator < (const student& b){
        return this->score<b.score;
    }
};
vector<student> students;
void solve(){
    int n;
    cin>>n;
    while(n--){
        student s;
        cin>>s.name>>s.code>>s.score;
        students.push_back(s);
    }
    sort(students.begin(),students.end());
    cout<<students.back().name<<" "<<students.back().code<<endl;
    cout<<students.front().name<<" "<<students.front().code<<endl;
}
int main(){
    solve();
    return 0;
}

sort一把梭,用vector存结构体,非常省事。

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄