백준/Class3
[백준] Class3-패션왕 신해빈 C++ 9375번
taene_
2023. 10. 9. 13:42
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<map>
using namespace std;
int main()
{
int t;
int n;
string a, b;
cin >> t;
while (t--)
{
map<string, int> m;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a >> b;
m[b]++;
}
int answer = 1;
for (auto iter = m.begin(); iter != m.end(); iter++) //auto==map<string, int>m::iterator
{
if (iter->second > 0)
{
answer *= iter->second + 1;
}
}
cout << answer - 1 << '\n';
}
return 0;
}
접근방법: 문자열을 구분해서 각 의상마다의 개수를 map을 저장하고 for문으로 (각 의상의 개수 + 1)을 모두 곱한 경우의 수에 1을 빼준다.