풀이과정
의상의 종류마다 개수를 카운트 해준다.
의상의 종류에 그 의상을 입지 않는 경우의 수를 더해서 모두 곱해주고
모두 안 입은 경우의 수 1가지를 빼준다.
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 0;
map <string, int> m;
for(int i = 0; i < clothes.size(); i++){
m[clothes[i][1]]++;
}
int sum = 1;
for(auto i : m){
sum *= i.second + 1;
}
answer = sum - 1;
return answer;
}
'🍞 Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스][Level2] 최솟값 만들기 c++ (0) | 2022.10.20 |
---|---|
[프로그래머스][Level2] 최댓값과 최솟값 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 숫자의 표현 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 멀리 뛰기 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 더 맵게 c++ (0) | 2022.10.20 |