# 생각

map을 이용하여 종류별로 카운트를 해주고

선택하지 않는 경우의 수도 존재하므로 각 종류의 개수 + 1을 곱해주면 전체 경우의 수를 얻어낼 수 있다

 

예를 들어, 상의 2가지, 하의 1가지가 존재한다면

선택하지 않는 경우까지 포함하여 3 * 2 = 6 가지의 경우의 수가 나온다

단, 문제의 조건에서 둘다 선택하지 않는 경우는 없으므로 -1을 해줘야 한다

 

 

# 전체 코드

#include <bits/stdc++.h>
using namespace std;

int solution(vector<vector<string>> clothes) {
	int answer = 1;

	map<string, int> m;
	for (auto& type : clothes) m[type[1]]++;
	for (auto iter = m.begin(); iter != m.end(); iter++) answer *= iter->second + 1;

	return answer - 1;
}

 


출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

+ Recent posts