sort的自定义“规则函数”

找最小数

http://www.nowcoder.com/questionTerminal/72d0910e837a4a6e95c7f4d60e6d0e68

#include<bits/stdc++.h>
using namespace std;


int n;
static const int maxn=1e5+5;
vector<pair<int,int> > solve;

//根据题目定义的规则函数 
bool cmp(pair<int,int> a, pair<int,int> b)
{
    if( a.first!=b.first )
    {
        return a.first<b.first;
    }
    else
    {
        return a.second<b.second;
    }
}


int main()
{
    while( ~scanf("%d",&n) )
    {
        for(int i=0; i<n; ++i)
        {
            pair<int,int> temp;
            scanf("%d%d",&temp.first,&temp.second);
            solve.push_back( temp ); 
        }

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

        printf("%d %d\n",solve[0].first, solve[0].second);

    }


    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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