题解 | #竞赛技巧#

竞赛技巧

https://ac.nowcoder.com/acm/problem/15056

难点一 : 如何储存三个数的形式呢?

	vector<pair<pair<int, int>, int>> times;

难点二 : 如何进行升序排列和降序排列的const写法呢

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main (){
    int n ;
    cin >> n;
    vector<pair<pair<int, int>, int>> times;

    for (int i = 0; i < n; i++) {
        int h, m, s;
        cin >> h >> m >> s;
        times.push_back({{h, m}, s});
    }

    sort(times.begin(), times.end(), [](const auto& a, const auto& b) {
        if (a.first.first != b.first.first) 
            return a.first.first < b.first.first;
        if (a.first.second != b.first.second) 
            return a.first.second < b.first.second;
        return a.second < b.second; //上述的<改成>就会进行降序排列
    });

    for (const auto& time : times) {
        cout << time.first.first << " " << time.first.second << " " << time.second << endl;
    }

    return 0;
}
全部评论

相关推荐

09-17 20:37
已编辑
长沙学院 Java
涂莱:学院本重心后移,金10银11,甚至金11银12,战线拉长一点,对于学院本来说秋招是个持久战,加油吧
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务