题意
给定若干个人和年龄信息,求合法区间里的最大年龄和最小年龄。
思路
拿string
随便搞搞呗。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<pair<string, string>> person;
string lo = "1814/09/06", hi = "2014/09/06";
for (int i = 0; i < n; ++i) {
string name, d;
cin >> name >> d;
if (d < lo || d > hi) continue;
person.emplace_back(d, name);
}
if (person.size() == 0) {
cout << "0\n";
exit(0);
}
sort(person.begin(), person.end());
cout << person.size() << ' ';
cout << person[0].second << ' ';
cout << person[person.size() - 1].second << '\n';
return 0;
}
HINT
不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !