티스토리 뷰

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42578

 

1. map 에 옷의 종류와 종류에 있는 옷의 수를 저장한다

2. map 의 값을 모두 1씩 더하고 다 곱해주면 모든 경우의 수가 나온다

3. 모두 안입는 경우 1개를 빼면 끝

#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int solution(vector<vector<string>> clothes) {
    int answer = 1;
    map<string, int> m;
    for(int i = 0; i < clothes.size(); i++){
        m.insert(make_pair(clothes[i][1], 0));
    }
    for(int i = 0; i < clothes.size(); i++) {
        m[clothes[i][1]] += 1;
    }
    for(auto i : m){
        answer *= i.second+1;
    }
    return answer-1;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함