// 02-找最小數.cpp: 定義控制檯應用程序的入口點。
//
#include "stdafx.h"
#include "iostream"
#include "algorithm"
using namespace std;
struct pairnum
{
int x;
int y;
};
bool cmp(pairnum a, pairnum b)
{
if (a.x != b.x) //那麼這樣的話,就是由小到大排序
return a.x < b.x;
else
return a.y < b.y; //輸出y小的那個數來
}
int main()
{
/*第一行輸入一個數n,1 <= n <= 1000,下面輸入n行數據,每一行有兩個數,分別是x y。
輸出一組x y,該組數據是所有數據中x最小,且在x相等的情況下y最小的。 */
int n,cnt;
int x, y;
pairnum p[1050];
//實現對輸入數據的接收部分
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i].x >> p[i].y;
}
//就是相當於有個優先級次序
sort(p, p + n, cmp);
cout << p[0].x << " " << p[0].y;
system("pause");
return 0;
}
先挖坑,日後再進行補充