• 문제 링크
https://www.acmicpc.net/problem/1764
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Main {
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Set<String> set = new HashSet<>();
int n = read(), m = read();
while (n-- > 0) set.add(readStr());
List<String> list = new ArrayList<>();
while (m-- > 0) if (set.contains(readStr())) list.add(sb.toString());
Collections.sort(list);
sb.setLength(0);
sb.append(list.size()).append('\n');
for (String s : list) sb.append(s).append('\n');
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
private static String readStr() throws IOException {
sb.setLength(0);
int c;
while ((c = System.in.read()) > 47) sb.append((char) c);
return sb.toString();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 5354 J박스 - Implementation / Java (0) | 2025.05.02 |
---|---|
[백준] 1270 전쟁 - 땅따먹기 - Data Structure / Java (0) | 2025.05.01 |
[백준] 15595 정답 비율 계산하기 - Data Structure / Java (0) | 2025.04.29 |
[백준] 11531 ACM 대회 채점 - Data Structure / Java (0) | 2025.04.28 |
[백준] 24448 図書館 2 (Library 2) - Data Structure / Java (0) | 2025.04.27 |
댓글