
์ค๋์ ๋ฐฑ์ค ํ์ ๋ฌธ์ ์๊ณ ์ด๊ฒ๋ ํด์๋งต์ผ๋ก ๊ฐ๋จํ ํ ์ ์์๋ค.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] nm = sc.nextLine().split(" ");
int N = Integer.parseInt(nm[0]);
int M = Integer.parseInt(nm[1]);
int result = 0;
Map<String, Integer> hm = new HashMap<>();
for(int i = 0; i < N; i++) {
int num = Integer.parseInt(sc.nextLine());
String[] students = sc.nextLine().split(" ");
for(int j = 0; j < num; j++) {
hm.put(students[j], hm.getOrDefault(students[j], 0) + 1);
}
}
for(Map.Entry<String, Integer> e : hm.entrySet()) {
if(e.getValue() >= M) {
result++;
}
}
// ๊ฒฐ๊ณผ ์ถ๋ ฅ
System.out.println(result);
}
}
ํด์๋งต ์ค์ ๋ฉ์๋ getOrDefault()๋ฅผ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง, ํด์๋งต ๋ฐ๋ณต๋ฌธ์ ์ด๋ป๊ฒ ์์ฑํ๋์ง ์๋ฉด ์ฝ๊ฒ ํ ์ ์๋ ๋ฌธ์ ์๋ค. ํด์๋งต ๋ฐ๋ณต๋ฌธ ์์ฑํ๋ ๊ฑด ๊ณ์ ํท๊ฐ๋ ธ๋๋ฐ ๊ณ์ ์ฌ์ฉํ๋ค๋ณด๋ ์ด์ ์์ ํ ์ธ์ด ๊ฒ ๊ฐ๋ค.
'์ฝ๋ฉํ ์คํธ > TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[99ํด๋ฝ] 12์ผ์ฐจ ๋ฌธ์ : ๋ง๋๊ธฐ (1) | 2025.02.04 |
---|---|
[99ํด๋ฝ] 11์ผ์ฐจ ๋ฌธ์ : ์คํ (0) | 2025.02.03 |
[99ํด๋ฝ] 9์ผ์ฐจ ๋ฌธ์ : ์ ์ฃผ ๋ฃ๊ณ ๋ ธ๋ ๋งํ๊ธฐ (0) | 2025.01.23 |
[99ํด๋ฝ] 8์ผ์ฐจ ๋ฌธ์ : ์ ๋ง๋ค ๋ง๋ (1) | 2025.01.22 |
[99ํด๋ฝ] 6์ผ์ฐจ ๋ฌธ์ : ํ ๋ฆฌ๊ฐ๋ฆฌ (0) | 2025.01.20 |
๋๊ธ