코딩테스트

프로그래머스 / 의상

murlocdev 2026. 7. 26. 00:04

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;
}