신입 개발자 공부 과정

프로그래머스 의상 C++ 본문

C++/공부

프로그래머스 의상 C++

Lewisjkim 2023. 12. 5. 18:45

#include <string>
#include <vector>
#include <unordered_map>
using namespace std;


int solution(vector<vector<string>> clothes)
{
	int answer{1};
	unordered_map<string, int> style;
	for (auto type : clothes)//type은 vecotr[x][]
	{
		style[type[1]]++;//clothes 이중 벡터에 들어있는2번쨰 인자 곧 type을 맵에 추가해준다. 
	}

	for (auto a : style)//a는 <stirng,int>
	{
		answer *= a.second+1;// 해당 부위를 입는 경우의 수 + 안입는 경우의 수
	}
	

	return answer-1;//아예 안입는 경우의 수
}

최소 1가지는 입어야 되기에 아무것도 안입는 경우의 수(1개)를 뺏다.