프로그래머스(Programmers)
코딩테스트 연습 > 해시 > 위장
cepiloth
2020. 2. 6. 16:32
반응형

https://programmers.co.kr/learn/courses/30/lessons/42578
코딩테스트 연습 - 위장 | 프로그래머스
programmers.co.kr
키워드 - 구현, 해시
Source
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int solution(vector<vector<string>> clothes) {
int answer = 1;
map<string, int> mm;
vector<string> arr;
for(int i=0; i<clothes.size(); i++) {
if(mm[clothes[i][1]] == 0) {
mm[clothes[i][1]] = 1;
arr.push_back(clothes[i][1]);
} else {
mm[clothes[i][1]]++;
}
}
for(int i=0; i<arr.size(); i++) {
answer *= (mm[arr[i]]+1);
}
return answer-1;
}
반응형