problem solving

[프로그래머스]위장

Shinuk Yi 2020. 3. 12. 16:21

각 종류마다 옷의 개수를 세고

각각의 종류를 착용하지 않을 경우까지 고려해 +1을 한후

모든 종류의 옷 개수를 곱한다.

여기서 모두 착용하지 않았을 경우를 빼면 답을 구할 수 있다.

#include <string>
#include <vector>
#include <map>
 
using namespace std;
 
int solution(vector<vector<string>> clothes) {
    map<stringint> mainMap;
    
    for(int idx = 0; idx < clothes.size(); idx++) {
        mainMap[clothes[idx][1]]++;
    }
    
    int answer = 1;
    for(auto it = mainMap.begin(); it != mainMap.end(); it++) {
        answer *= it->second + 1;
    }
 
    answer--;
    return answer;
}
cs