그럴듯한 개발 블로그
반응형

https://school.programmers.co.kr/learn/courses/30/parts/12077

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

int solution(vector<vector<string>> clothes) {
    int answer = 1;
    unordered_map<string, int>  map;
    vector<string>              type;
    
    for (int i = 0; i < clothes.size(); i++)
    {
        if (map.find(clothes[i][1]) == map.end())
        {
            map[clothes[i][1]] = 2; // map에 2 등록해줌
            type.push_back(clothes[i][1]);
        }
        else
            map[clothes[i][1]] += 1; // 개수 1 더해줌
    }
    for (int i = 0; i < type.size(); i++)
        answer *= map[type[i]]; 
    return answer - 1;
}

unordered_map에 대해 공부하니 쉽게 풀 수 있었다😀

반응형
profile

그럴듯한 개발 블로그

@donghyk2

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!