[Programmers] 의상(Lv.2)(C++)

Alice·2023년 8월 20일
0

풀이 소요시간 : 15분

입은 옷의 총 숫자가 0개만 아니면 되니까 (A + 1) * (B + 1) * (C + 1) - 1 의 수식만 적용하면 쉽게 풀리는 문제였다. map<string, vector<string>> 을 쓰는게 가장 간단할 것 같아서 사용했다.


전체 코드

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

unordered_map<string, vector<string>> Map;

int solution(vector<vector<string>> clothes) {
    for(vector<string> v : clothes)
    {
        Map[v[1]].push_back(v[0]);
    }
    
    int total = 1;
    for(auto E : Map)
    {
        total *= (E.second.size() + 1);
    }
    return total - 1;
    
}
profile
SSAFY 11th

0개의 댓글