题解 | #找最小数#结构体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;
}

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

包含考研机试打卡表题目

全部评论

相关推荐

09-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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