[프로그래머스] 위장 - (해시) c++

ha·2022년 1월 10일
0

프로그래머스

목록 보기
6/21


map 사용 풀이

int solution(vector<vector<string>> clothes) {
    map <string,int> m;
    int answer = 1;
    for(vector <string> c: clothes){
        m[c[1]]++;
    }
    for(auto it=m.begin();it!=m.end();it++){
        answer*= (it->second + 1);
    }
    return answer-1;
}

상의가 스웨터, 반팔, 와이셔츠 이렇게 3 종류가 있다면 가능한 경우의 수는 스웨터, 반팔, 와이셔츠, 아무것도 선택 안 함 이렇게 4가지가 있다.

0개의 댓글