题解 | #找最小数#
找最小数
https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
//用类来存储x,y,通过vector存储,利用sort按照排序要求排序后输出vector[0]即可
class XY
{
public: int x;
int y;
XY(int x,int y)
{
this->x=x;
this->y=y;
}
void show()
{
cout<<x<<" "<<y<<endl;
}
};
bool cmp(XY a,XY b)
{
if(a.x!=b.x) return a.x<b.x;
else return a.y<b.y;
}
int main() {
int n;
vector<XY> v;
cin >>n;
for(int i=0;i<n;i++) { // 注意 while 处理多个 case
int a,b;
cin>>a>>b;
XY xy(a,b);
v.push_back(xy);
}
sort(v.begin(), v.end(),cmp);
v[0].show();
}
// 64 位输出请用 printf("%lld")
