백준 1764번(Java)

박은지·2025년 3월 4일
0

백준

목록 보기
42/89
post-thumbnail

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs = br.readLine().split(" ");
		
		int n = Integer.parseInt(inputs[0]);
		int m = Integer.parseInt(inputs[1]);
		
		HashSet<String> set = new HashSet<>();
		for(int i=0; i<n; i++) {
			set.add(br.readLine());
		}
		
		ArrayList<String> result = new ArrayList<>();
		for(int i=0; i<m; i++) {
			String str = br.readLine();
			if(set.contains(str)) {
				result.add(str);
			}
		}
		
		Collections.sort(result);
		System.out.println(result.size());
		for(String s:result) {
			System.out.println(s);
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글