1일1알

백준 1380번 귀걸이 C++ 본문

알고리즘

백준 1380번 귀걸이 C++

영춘권의달인 2022. 4. 25. 10:35

출처 : https://www.acmicpc.net/problem/1380

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;
using ll = long long;

int dRow[4] = { -1,0,1,0 };
int dCol[4] = { 0,1,0,-1 };

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

	int cnt = 1;
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		vector<string> v(n + 1);
		map<string, int> mp;
		cin.ignore();
		for (int i = 1; i <= n; i++) {
			getline(cin, v[i]);
		}
		for (int i = 0; i < 2 * n - 1; i++) {
			int num;
			char c;
			cin >> num >> c;
			mp[v[num]]++;
		}
		string name = "";
		for (auto a : mp) {
			if (a.second == 1)
				name = a.first;
		}
		cout << cnt << " " << name << "\n";
		cnt++;
	}
};

'알고리즘' 카테고리의 다른 글

백준 1421번 나무꾼 이다솜 C++  (0) 2022.04.27
백준 1385번 벌집 C++  (0) 2022.04.26
백준 1347번 미로 만들기 C++  (0) 2022.04.24
백준 1337번 올바른 배열 C++  (0) 2022.04.23
백준 1331번 나이트 투어 C++  (0) 2022.04.22