题目链接

​https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd?tpId=67&tqId=29645&tPage=1&ru=/kaoyan/retest/1005&qru=/ta/bupt-kaoyan/question-ranking​

题目描述

第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。 

输入描述:

输入有多组数据。
每组输入n,然后输入n个整数对。

输出描述:

输出最小的整数对。

示例1

输入

复制

5  
3 3
2 2
5 5
2 1
3 6

输出

复制

2 1

题解:

简单结构体排序

#include <iostream>
#include <algorithm>
using namespace std;
struct data{
int x;
int y;
}buf[1000];
bool cmp(data a, data b){
if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
}
int main(){
int n;
while(cin >> n){
for(int i = 0; i < n; i++){
cin >> buf[i].x >> buf[i].y;
}
sort(buf, buf + n, cmp);
cout << buf[0].x << " " << buf[0].y << endl;
}
return 0;
}