题解 | #找最小数#结构体sort

找最小数

https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd

结构体sort

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct stc {
    int x;
    int y;
};

//快排不交换时返回true
bool cmp(stc s1, stc s2) {
    if (s1.x < s2.x) return true;

    if (s1.x == s2.x && s1.y < s2.y) return true;

    return false;
}

int main() {

    int n;
    cin >> n;

    vector<stc> vec;
    while (n--) {
        int x, y;
        cin >> x >> y;
        vec.push_back({x, y});
    }

    sort(vec.begin(), vec.end(), cmp);

    cout << vec[0].x << " " << vec[0].y << endl;

    return 0;
}

王道考研机试 文章被收录于专栏

包含考研机试打卡表题目

全部评论

相关推荐

点赞 评论 收藏
分享
菠落蜜:这个是系统自动投的,不是hr主动打招呼。更抽象的还有ai回复
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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