zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    while循环学习之统计流量
    MySQL的启动脚本
    UVA 725 Division
    UVA 712 S-tree
    UVA 514
    字典树
    UVA 1595 multimap 的应用
    C++ map 和 multimap
    浮点数
    UVA 227
  • 原文地址:https://www.cnblogs.com/MarkKobs-blog/p/10550423.html
Copyright © 2011-2022 走看看