#include <string> #include <vector> #include <map> using namespace std; int solution(vector<vector<string>> clothes) { map<string, int> m; // 옷 종류 개수 저장할 맵 vector<string> name; // 옷 종류 이름 저장할 벡터 for(int i = 0; i < clothes.size(); i++) { // 옷 종류 이름 저장한적 없으면 if(m[clothes[i][1]] == 0) { name.push_back(clothes[i][1]); } m[clothes[i][1]]++; } // (옷 1번 개수+안입었을때) * (옷 2번 개수+안입었을때) * (옷 3번 개수+안입었을때) .... -1(아무것도 안입었을때) int result = 1; for(int i = 0; i < name.size(); i++) { result *= (m[name[i]]+1); } result -= 1; return result; } | cs |
'Programmers > Level 2' 카테고리의 다른 글
[프로그래머스 2] 쇠막대기 (C/C++) (★★) (1) | 2019.10.24 |
---|---|
[프로그래머스 2] 올바른 괄호 (C/C++) (1) | 2019.10.24 |
[프로그래머스 2] 다리를 지나는 트럭 (C/C++) (★★) (3) | 2019.10.24 |
[프로그래머스 2] 타겟 넘버 (C/C++) (0) | 2019.10.23 |
[프로그래머스 2] 카펫 (C/C++) (0) | 2019.10.23 |