728x90
반응형
#include <iostream>
#include <vector>;
#include <string>;
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >>n;
vector<pair<pair<int, int>,pair<int,string>>>name(n);
for (int i = 0; i < n; i++) {
cin >> name[i].second.second >> name[i].second.first >> name[i].first.second>>name[i].first.first;
}
sort(name.begin(), name.end());
cout << name[n - 1].second.second << '\n' << name[0].second.second << '\n';
}
vector 내에 여러 개의 숫자와 문자를 넣을 때 pair를 여러 개 넣어도 된다고 한다.
https://hydroponicglass.tistory.com/33
[C++, STL] 구조체, pair 벡터 정렬
다른 글 [C++, STL] 알고리즘 문제풀이를 위한 벡터(vector) [C++, STL] 알고리즘 문제풀이를 위한 pair [C++, STL] 우선순위 큐(priority queue) 비교연산자 구현 서론 벡터에 들어갈 수 있는 자료형에 pair와 st..
hydroponicglass.tistory.com
sort를 사용할 때 pair의 first를 기준으로 정렬되기에 연도를 first.first로 구성.
93년생이 제일 어리기에 name [n-1]을 먼저 출력한다.
728x90
반응형