Baekjoon - 1764

Tadap·2023년 10월 1일
0

Baekjoon

목록 보기
35/94
post-custom-banner

문제

Solved.ac class3

1차시도

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		String[] split = br.readLine().split(" ");

		int n = Integer.parseInt(split[0]);
		int m = Integer.parseInt(split[1]);

		HashSet<String> aSet = new HashSet<>();
		HashSet<String> bSet = new HashSet<>();
		LinkedList<String> duplicatedList = new LinkedList<>();

		for (int i = 0; i < n; i++) {
			aSet.add(br.readLine());
		}

		for (int i = 0; i < m; i++) {
			bSet.add(br.readLine());
		}

		for (String s : aSet) {
			if (bSet.contains(s)) {
				duplicatedList.add(s);
			}
		}
		sb.append(duplicatedList.size()).append("\n");

		duplicatedList.sort(Comparator.naturalOrder());
		for (String s : duplicatedList) {
			sb.append(s).append("\n");
		}

		System.out.println(sb);

	}
}

성공

post-custom-banner

0개의 댓글