본문 바로가기

problem solving

[프로그래머스]위장

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

각각의 종류를 착용하지 않을 경우까지 고려해 +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

'problem solving' 카테고리의 다른 글

[프로그래머스]카펫  (0) 2020.03.12
[프로그래머스]베스트앨범  (0) 2020.03.12
[프로그래머스]구명보트  (0) 2020.03.11
[프로그래머스]괄호 변환  (0) 2020.03.10
[프로그래머스]숫자 야구  (0) 2020.03.10