본문 바로가기
알고리즘/자료 구조

백준 9375번 : 패션왕 신해빈

by Jason95 2021. 1. 22.

문제 링크 : www.acmicpc.net/problem/9375

내 풀이(2021.1.22.) :

#include <iostream>
#include <map>

using namespace std;

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

	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		map<string, int> m;
		int n; cin >> n;
		for (int i = 0; i < n; i++) {
			string temp, temp2; cin >> temp >> temp2;
			if (m.find(temp2) == m.end()) m[temp2] = 1;
			else m[temp2] = m[temp2] + 1;
			//cout << "   " << m[temp2] << endl;
		}
		int res = 1;
		for (auto it = m.begin(); it != m.end(); it++) {
			res *= (it->second + 1);
			//cout << "--- " << it->second << endl;
		}
		cout << res - 1 << endl;
	}

	return 0;
}