游客 Signup | Login
中文 | En

1592 - 找最小数


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

<br />

Input


输入有多组数据。<br />

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

<br />

Output


输出最小的整数对。

<br />

Examples

Input

1
35 68
5
25 70
59 79
65 63
46 6
28 82

Output

35 68
25 70

Solution C

#include<stdio.h>
#include<string.h>
#include<math.h>
main(){
	int n,i,num,min1,min2,k1,k2;
	while(scanf("%d",&n)!=EOF){
		scanf("%d%d",&min1,&min2);
		for(i=1;i<n;i++){
			scanf("%d%d",&k1,&k2);
			if(k1<min1){
				min1=k1;
				min2=k2;
			}else if(k1==min1){
				if(k2<min2){
					min2=k2;
				}
			}
		}
		printf("%d %d\n",min1,min2);
	}
	return 0;
}

Solution C++

//北邮2010计算机:1170:找最小数
//(1<=n<=1000)
#include <fstream>
#include <algorithm>
#include <iostream>
using namespace std;
struct NUMBER{
	int x, y;
};
NUMBER a[1000];

bool cmp( NUMBER a, NUMBER b ){
	if( a.x == b.x )
		return a.y < b.y;
	else return a.x < b.x;

};

int main()
{
	int i, j, k, n, m;
		while( cin >> n ){
		for( i=0; i<n; i++ )
			cin >> a[i].x >> a[i].y;
		sort(a,a+n,cmp);
		cout << a[0].x << " " << a[0].y << endl;
	}
		return 0;
}
Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题