728x90
    
    
  [Level 2]

내 풀이
옷의 종류와 개수를 담는 <string, int> unordered_map을 만든다.
예를 들어 얼굴 2, 상의 1, 하의 1 일 경우를 생각해보면 안 입는 경우를 0으로 두어 (0,1,2), (0,1), (0,1) 을 갖는다고 생각할 수 있다.
적어도 하나 이상은 입으므로 (옷 종류마다의 개수+1)끼리 곱한 후 전부 0인 경우 1가지를 빼주면 된다. (3*2*2 - 1 = 11)
int solution(vector<vector<string>> clothes) {
	int answer = 1;
	unordered_map<string, int> map;
	for (auto i : clothes) {
		map[i[1]]++;
	}
	for (auto i : map) {
		answer *= i.second + 1;
	}
	return answer - 1;
}

'[C_C++]코딩테스트 연습 > [프로그래머스] level 2' 카테고리의 다른 글
| [프로그래머스] 프린터 (pair, priority queue) - C++ 스택&큐 (0) | 2021.10.18 | 
|---|---|
| [프로그래머스] 기능개발 - C++ 스택&큐 (0) | 2021.10.17 | 
| [C++] 프로그래머스 hash 2 - 전화번호 목록 (0) | 2021.10.17 | 
| [C++] 프로그래머스 hash 1- 완주하지 못한 선수 (vector만 이용 / 해시 이용) (0) | 2021.06.14 | 
![[C++] 프로그래머스 hash 2 - 위장](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FcagGmh%2FbtrhVZRXdv5%2FAAAAAAAAAAAAAAAAAAAAADIbt6nGaSkFJvg4ZFHLwwg_OJgV83jKnFWIuofimBqe%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1761922799%26allow_ip%3D%26allow_referer%3D%26signature%3DVgiYSGxgWv66jIZtj1ILoOyMfu4%253D)