https://school.programmers.co.kr/learn/courses/30/lessons/42578
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
옷을 종류별로 정리해야 하기 때문에
해시를 사용하는 unordered_map을 이용해 해결했다
더보기
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
unordered_map<string, int> umClothes;
// 옷의 종류별 개수를 unordered_map에 저장
for (int i = 0; i < clothes.size(); ++i)
{
umClothes[clothes[i][1]]++;
}
// 각 옷의 종류별 개수 + 1(안 입는 경우)을 곱한 후
// 한 부위는 무조건 입기 때문에 1을 빼서 계산
for (auto it = umClothes.begin(); it != umClothes.end(); ++it)
{
answer *= (it->second + 1);
}
answer -= 1;
return answer;
}
'코딩테스트' 카테고리의 다른 글
| 프로그래머스 / 프로세스 (0) | 2026.08.03 |
|---|---|
| 프로그래머스 / 베스트앨범 (0) | 2026.07.29 |
| 프로그래머스 / 전화번호 목록 (0) | 2026.07.22 |
| 프로그래머스 / 완주하지 못한 선수 (0) | 2026.07.20 |
| 프로그래머스 / 폰켓몬 (0) | 2026.07.20 |