Algorithm/C++
[백준 5635번] 생일
imagineer_jinny
2022. 4. 9. 13:00
5635번: 생일
어떤 반에 있는 학생들의 생일이 주어졌을 때, 가장 나이가 적은 사람과 가장 많은 사람을 구하는 프로그램을 작성하시오.
www.acmicpc.net
pair 두개 말고 여러개 쓰고 싶을 땐 어떻게 쓰는지
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를 사용할 때 pair의 first를 기준으로 정렬되기에 연도를 first.first로 구성.
93년생이 제일 어리기에 name [n-1]을 먼저 출력한다
[C++, STL] 구조체, pair 벡터 정렬 - 코드 다이어리 (tistory.com)
[C++, STL] 구조체, pair 벡터 정렬
다른 글 [C++, STL] 알고리즘 문제풀이를 위한 벡터(vector) [C++, STL] 알고리즘 문제풀이를 위한 pair [C++, STL] 우선순위 큐(priority queue) 비교연산자 구현 서론 벡터에 들어갈 수 있는 자료형에 pair와 st..
hydroponicglass.tistory.com
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
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';
return 0;
}