나의 브을로오그으

[c++] 9375번 : 패션왕 신해빈 본문

알고리즘/BaekJoon

[c++] 9375번 : 패션왕 신해빈

__jhp_+ 2022. 8. 31. 15:29

https://www.acmicpc.net/problem/9375

 

9375번: 패션왕 신해빈

첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로   (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>

using namespace std;

#define MAX_CATEGORY		30

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

	unordered_map<string, int> map;
	vector<int> vec;
	vec.reserve(MAX_CATEGORY);
	int T, N;
	string name, category, delim = " ";
	int pos = 0, result = 1;

	cin >> T;
	for (int i = 0; i < T; ++i)
	{
		cin >> N;
		cin.ignore();
		for (int j = 0; j < N; ++j)
		{
			cin >> name >> category; // name not using
			if (map.find(category) == map.end())
			{
				map.insert({ category, 1 });
			}
			else
			{
				++map[category];
			}
		}

		unordered_map<string, int>::iterator iter = map.begin();
		while (iter != map.end()) 
		{
			result *= (iter->second + 1);
			++iter;
		}
		cout << result - 1 << '\n';

		map.clear();
		result = 1;
	}

	return 0;
}

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

[c++] 11047번 : 동전 0  (0) 2022.09.02
[c++] 9461번 : 파도반 수열  (0) 2022.09.02
[c++] 9095번 : 1, 2, 3 더하기  (0) 2022.08.30
[c++] 5430번 : AC  (0) 2022.06.30
[c++] 2667번 : 단지번호붙이기  (0) 2022.06.28