题解 | #找最小数#

找最小数

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

#include <bits/stdc++.h>

using namespace std;
struct Couple {
    int x;
    int y;
};

bool Compare(Couple lhs, Couple rhs) {
    if (lhs.x < rhs.x) {
        return true;
    } else if (lhs.x == rhs.x && lhs.y < rhs.y) {
        return true;
    } else {
        return false;
    }
}

int main() {
    int n;//n个数据对
    int x;
    int y;
    //找到MinX,再在MinX里面找MinY
    scanf("%d", &n);
    Couple input[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &input[i].x, &input[i].y);
    }

    for (int i = 0; i < n; ++i) {
        sort(input, input + n, Compare);
    }

    printf("%d %d", input[0].x, input[0].y);
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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