[BOJ 9375] 패션왕 신해빈

xeonu·2022년 7월 1일
0

코딩테스트

목록 보기
3/7
post-thumbnail

문제링크

소스코드

#include <string>
#include <iostream>
#include <map>
using namespace std;

int main() {
    string str1, str2;
    int t, m;
    cin>>t;
    while(t--){
        map<string, int> _map;
        cin>>m;
        while(m--){
            cin>>str1>>str2;
            _map[str2]++;
        }
        int ans = 1;

        for(auto iter : _map){
            ans*=(iter.second+1);
        }
        cout<<--ans<<endl;
    }
}

map에서 탐색을 할 때는 auto를 사용하면 편리하다.
2개의 선글라스 3개의 상의가 있다고 가정하면 선글라스가 0, 1, 2번
상의가 0, 1, 2, 3번 이런식으로 종류가 나뉜다고 생각하면
총 3 * 4 = 12의 조합이 나오고 알몸인 경우인 {0, 0}인 경우를 빼면
12-1 = 11개가 나온다.

profile
백엔드 개발자가 되기위한 여정

0개의 댓글