[프로그래머스 / C++] 의상

Taegang Yun·2023년 9월 5일
1

https://school.programmers.co.kr/learn/courses/30/lessons/42578


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

using namespace std;

map<string, int> TypeOfCloth;


int solution(vector<vector<string>> clothes) {
    int answer = 0;
    int tmp = 1;
    
    for(int i = 0 ; i < clothes.size() ; i++)
    {
        TypeOfCloth[clothes[i][1]]++;
    }
    if(TypeOfCloth.size() == 1){
        for(pair<string, int> x : TypeOfCloth)
        {
            answer = x.second;
        }
    }
    else
    {
        for(pair<string, int> x : TypeOfCloth)
        {
            tmp *= (x.second+1);
        }
        tmp--;
        answer = tmp;
    }
    
    
    
    
    return answer;
}

옷 조합을 할 수 있는 경우가.. 종류가 한 종류면 그 종류 개수만큼이고
여러 개면 옷 종류별로+1 해서 곱해준다음 아예 안 입을 경우 1 빼면 되니까 그 논리로 바로 짰다

1트 해결!!

profile
언젠간 전문가가 되겠지

0개의 댓글

관련 채용 정보