해시맵을 이용해서 키워드가 있는지 없는지 알아내고 있다면 카운트를 하나씩 까주는식으로 구현하면 된다.
import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
int n, m;
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
Map<String, Boolean> map = new HashMap<>();
for (int i = 0; i < n; i++) {
map.put(br.readLine(), true);
}
int cnt = n;
for (int i = 0; i < m; i++) {
st = new StringTokenizer(br.readLine(), ",");
while (st.hasMoreTokens()) {
String s = st.nextToken();
if (map.containsKey(s)) {
map.remove(s);
cnt--;
}
}
bw.write(cnt + "\n");
}
bw.flush();
}
}