Print
카테고리: [ Algorithm ]
조회수: 5687

1. 문제

스파이들은 매일 다른 옷을 조합하여 입어 자신을 위장합니다.

예를 들어 스파이가 가진 옷이 아래와 같고 오늘 스파이가 동그란 안경, 긴 코트, 파란색 티셔츠를 입었다면 다음날은 청바지를 추가로 입거나 동그란 안경 대신 검정 선글라스를 착용하거나 해야 합니다.

[ 제한사항 ]

2. 코드

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Camouflage {
    public static void main(String[] args) {
        // String[][] clothes = { { "yellow_hat", "headgear" }, { "blue_sunglasses", "eyewear" }, { "green_turban", "headgear" } };
        String[][] clothes = { { "crow_mask", "face" }, { "blue_sunglasses", "face" }, { "smoky_makeup", "face" } };

        Camouflage camouflage = new Camouflage();
        System.out.println(camouflage.count(clothes));
    }

    private int count(String[][] clothes) {
        Map<String, Integer> map = new HashMap<String, Integer>();
        int answer = 1;

        for (int i = 0; i < clothes.length; i++) {
            String key = clothes[i][1];

            if (map.containsKey(key)) {
                map.put(key, map.get(key) + 1);
            } else {
                map.put(key, 1);
            }

        }

        for (String k : map.keySet()) {
            System.out.println(k + "=" + map.get(k));
        }

        Iterator<Integer> it = map.values().iterator();
        while (it.hasNext()) {
            int j = it.next().intValue();
            System.out.println(j);
            answer *= j + 1;
        }
        return answer - 1;
    }
}