logo头像

往者不可谏,来者犹可追。

牛客-北邮-找最小数

题目描述

第一行输入一个数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


分析

开始想用结构体把数先存下来再做比较,觉得结构体排序有点繁琐。观察题目再没有别的要求,于是就没有把数存都存下来,只存了最大。输入完结果也就出来了。


代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
int n;
while(scanf("%d",&n)!=EOF){
int a, b, ansA,ansB;
scanf("%d%d",&ansA,&ansB);
for(int i = 1; i < n; i ++){
scanf("%d%d",&a,&b);
if(a<ansA){
ansA = a;
ansB = b;
}
if(a==ansA&&b<ansB){
ansB = b;
}
}
printf("%d %d\n",ansA,ansB);
}
return 0;
}
上一篇