백준 5635 c++

magicdrill·2024년 4월 16일
0

백준 문제풀이

목록 보기
310/654

백준 5635 c++

여러 조건을 봐야하는 정렬문제이다. 평일에는 부트캠프 복습을 위해 쉬운거만 하려고 했는데 브루트포스문제를 안풀어 버릇해서 그런지 너무 어렵다... 브루트 포스도 다시 시작해야겠다.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_list(vector < pair<vector<int>, string>> &name_list)
{
	int n, i;
	string name;
	int dd, mm, yyyy;
	
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> name >> dd >> mm >> yyyy;
		name_list.push_back({ {dd, mm, yyyy}, name });
	}

	return;
}

bool compare(pair<vector<int>, string> A, pair<vector<int>, string> B)
{
	//[0] = dd
	//[1] = mm
	//[2] = yyyy
	if (A.first[2] > B.first[2])//클수록 어림
	{
		return true;
	}
	else if(A.first[2] == B.first[2])
	{
		if (A.first[1] > B.first[1])//클수록 어림
		{
			return true;
		}
		else if (A.first[1] == B.first[1])
		{
			if (A.first[0] > B.first[0])//클수록 어림
			{
				return true;
			}
			else if (A.first[0] == B.first[0])
			{

			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}

void find_answer(vector < pair<vector<int>, string>> &name_list)
{
	sort(name_list.begin(), name_list.end(), compare);//어린사람부터 오름차순으로 정렬할거야

	cout << name_list.front().second << "\n";
	cout << name_list.back().second << "\n";

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	vector < pair<vector<int>, string>> name_list;

	input_list(name_list);
	find_answer(name_list);

	return 0;
}

0개의 댓글