• B1004. 成绩排名


    这一题总算是把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存结构体,非常省事。

    keep going
  • 相关阅读:
    SpringBoot项目设置maven打包时间
    SpringBoot热部署配置
    Git笔记
    SpringBoot LogBack日志配置
    CURL使用教程
    Linux 安装Docker及使用
    转发和重定向的区别
    16周作业
    16
    15周
  • 原文地址:https://www.cnblogs.com/MarkKobs-blog/p/10550423.html
Copyright © 2020-2023  润新知