题解 | 找最小数

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

using std::cout;
using std::cin;
using std::endl;
using std::stable_sort;
using std::vector;

typedef struct pair{
    int x;
    int y;
}Pair;

bool cmp(Pair p1, Pair p2){
    if(p1.x == p2.x)
        return p1.y <= p2.y;
    return p1.x <= p2.x;
}

int main()
{
    int n;
    vector<Pair> vec;
    while(cin >> n){
        for(int i = 0; i < n; i++){
            Pair p;
            cin >> p.x >> p.y;
            vec.push_back(p);
        }
        stable_sort(vec.begin(),vec.end(),cmp);
        cout << vec[0].x << ' ' << vec[0].y << endl; 
    }

    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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