반응형

📖 문제

📋 코드
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int i = 0; i < T; i++) {
int N = sc.nextInt();
int ans = 1;
HashMap<String, Integer> map = new HashMap<>();
for (int j = 0; j < N; j++) {
String name = sc.next();
String type = sc.next();
if (map.get(type) == null) {
map.put(type, 1);
} else {
map.put(type, map.get(type) + 1);
}
}
for (int val : map.values()) {
ans *= (val + 1);
}
System.out.println(ans - 1);
}
}
}
👨🏻💻 결과

🔗 링크
https://www.acmicpc.net/problem/9375
9375번: 패션왕 신해빈
첫 번째 테스트 케이스는 headgear에 해당하는 의상이 hat, turban이며 eyewear에 해당하는 의상이 sunglasses이므로 (hat), (turban), (sunglasses), (hat,sunglasses), (turban,sunglasses)로 총 5가지 이다.
www.acmicpc.net
반응형
'🧩PS > 🥉Easy' 카테고리의 다른 글
[JAVA] 백준 10828번 - 스택 (0) | 2021.11.23 |
---|---|
[JAVA] 백준 1676번 - 팩토리얼 0의 개수 (0) | 2021.11.23 |
[JAVA] 백준 1010번 - 다리 놓기 (0) | 2021.11.18 |
[JAVA] 백준 11051번 - 이항 계수 2 (0) | 2021.11.18 |
[JAVA] 백준 11050번 - 이항 계수 1 (0) | 2021.11.18 |