백준 10546 c++

magicdrill·2024년 5월 11일

백준 문제풀이

목록 보기
345/673

백준 10546 c++

오랜만에 map컨테이너를 사용해본 문제이다. map 사용에 익숙치 않아서 vector를 사용해보려 했지만 시간초과가 발생했다.

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

using namespace std;

void input_marathoner(map<string, int>& marathoner/*vector<pair<string, bool>>& marathoner*/)
{
	int N, i, j;
	string name;

	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> name;
		//marathoner.push_back({ name, false });
		marathoner[name]++;
	}
	for (i = 0; i < N - 1; i++)
	{
		cin >> name;
		/*
		for (j = 0; j < marathoner.size(); j++)
		{
			if (marathoner[j].first == name && marathoner[j].second == false)
			{
				marathoner[j].second = true;
				break;
			}
		}
		*/
		marathoner[name]--;
	}

	return;
}

void find_answer(map<string, int> &marathoner/*vector<pair<string, bool>>& marathoner*/)
{
	int i;

	/*
	for (i = 0; i < marathoner.size(); i++)
	{
		if (marathoner[i].second == false)
		{
			cout << marathoner[i].first << "\n";
		}
	}
	*/
	for (auto it : marathoner)
	{
		if (it.second != 0)
		{
			cout << it.first << "\n";
		}
	}

	return;
}

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

	//vector<pair<string, bool>> marathoner;
	map<string, int> marathoner;

	input_marathoner(marathoner);
	find_answer(marathoner);

	return 0;
}

0개의 댓글