题解 | 找最小数

找最小数

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

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
struct xy1{
    int x;
    int y;
};
bool compare(xy1 lhs, xy1 rhs) {
    if (lhs.x == rhs.x) {
        return lhs.y <= rhs.y;
    }
    else {
        return lhs.x <= rhs.x;
    }
}
int main() {
    int n, x, y;
    while (scanf("%d", &n) != EOF) {
        vector<xy1> p(n);
        for (int i = 0; i < n; ++i) {
            scanf("%d%d", &x, &y);
            p[i].x=x;
            p[i].y = y;
        }
        sort(p.begin(), p.end(), compare);
        printf("%d %d", p[0].x, p[0].y);
        p.clear();
    }
    return 0;
}

#pieceofshit##shit#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务