의상

magicdrill·2025년 3월 3일
0

의상

백준 9375 "패션왕 신해빈"과 동일한 문제이다.
https://velog.io/@magicdrill/%EB%B0%B1%EC%A4%80-9375-java-Map
처음에 map<string, vector<string>> assortment;의 자료구조로 의상명을 전부 다 저장했는데, 종류별 개수만 저장하면 된다. 만약 의상명이 필요한 경우라면

for(auto temp : assortment){
	sum *= (temp.second.size() + 1);
}

로 구하면 될거 같다.

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

using namespace std;

//백준 9375 패션왕 신해빈과 동일한 문제
int solution(vector<vector<string>> clothes) {
    int answer = 0, sum;
    map <string, int> assortment;
    map <string, vector<string>> assortment2;
    int i, j;
    string category, detail;
    
    for(i = 0; i < clothes.size(); i++){
        category = clothes[i][1];
        assortment[category]++;
        
        //분류2
        detail = clothes[i][0];
        assortment2[category].push_back(detail);
    }
    
    cout << "분류 결과\n";
    for(auto temp : assortment){
        cout << temp.first << " : " << temp.second << "\n";
    }
    
    cout << "분류 결과2\n";
    for(auto temp : assortment2){
        cout << temp.first << " : ";
        for(auto cloth : temp.second){
            cout << cloth << " ";
        }
        cout << "\n";
    }
    
    //조합의 개수 구하기
    //입거나 안 입는 경우 조합
    sum = 1;
    for(auto temp : assortment){
        sum *= (temp.second + 1);
    }
    cout << sum << "\n";
    answer = sum - 1;
    cout << answer << "\n";
    
    //분류2 계산
    int sum2 = 1;
    for(auto temp : assortment2){
        sum2 *= (temp.second.size() + 1);
    }
    cout << sum2 << "\n";
    cout << sum2 - 1 << "\n";
    
    return answer;
}

0개의 댓글