题解 | #找最小数#结构体sort
找最小数
https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd
结构体sort
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct stc {
int x;
int y;
};
//快排不交换时返回true
bool cmp(stc s1, stc s2) {
if (s1.x < s2.x) return true;
if (s1.x == s2.x && s1.y < s2.y) return true;
return false;
}
int main() {
int n;
cin >> n;
vector<stc> vec;
while (n--) {
int x, y;
cin >> x >> y;
vec.push_back({x, y});
}
sort(vec.begin(), vec.end(), cmp);
cout << vec[0].x << " " << vec[0].y << endl;
return 0;
}
王道考研机试 文章被收录于专栏
包含考研机试打卡表题目


查看14道真题和解析