●문제

●입출력

사용 알고리즘 : Hash / unoredered_map
문제해석 : 옷 종류와 옷 가짓수를 생각해서 푸는 문제
옷 가짓수 + 1 의 경우를 다 곱해서 -1 을 해주면 답이나온다
아무것도 안입는 선택지 -1
똑같은 그 옷 종류를 안입는 경우 + 1을 해준다
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
int solution(vector<vector<string>> clothes)
{
int answer = 1;
//옷이름, 옷종류
//headgear -> yello_hat, green_turban
//eyewear -> blue_sunglasses
unordered_map<string, int>clothesMap;
for (auto c : clothes)
{
string type_Clothes = c[1];
clothesMap[type_Clothes]++;
}
//(입는경우 + 안입는경우)
for (auto it : clothesMap)
{
answer *= (it.second + 1);
}
//아에 아무것도 안입는경우는 제외
return answer -1;
}
레벨 : 2
점수 : 1
'C++ 프로그래머스 > Hash' 카테고리의 다른 글
| 프로그래머스(C++) - 전화번호 목록 (0) | 2025.08.08 |
|---|---|
| 프로그래머스(C++) - 완주하지 못한 선수 (0) | 2025.08.08 |
| Algorithm - Hash (0) | 2025.08.08 |
