题目
题目描述
第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。
输入描述
输入有多组数据。
每组输入n,然后输入n个整数对。
输出描述
输出最小的整数对。
示例
5
3 3
2 2
5 5
2 1
3 6
输出
2 1
代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct number
{
int x;
int y;
}num[1005];
int cmp(const void* a, const void * b)
{
struct number* aa = (struct number *)a;
struct number* bb = (struct number *)b;
if (aa->x != bb->x)
{
return aa->x > bb->x;
}
else
{
return aa->y > bb->y;
}
}
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
int i;
for (i = 0; i < n; i++)
{
scanf("%d%d", &num[i].x, &num[i].y);
}
qsort(num, n, sizeof(num[0]), cmp);
printf("%d %d\n", num[0].x, num[0].y);
}
return 0;
}