코딩/백준 알고리즘

1764번) 듣보잡

금손형아 2017. 11. 11. 19:47

문제 출처 : https://www.acmicpc.net/problem/1764


import java.util.Collections;

import java.util.HashSet;

import java.util.LinkedList;

import java.util.Scanner;


public class Q1764 {


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int noListen = sc.nextInt();

int noSee = sc.nextInt();

HashSet<String> noListenList = new HashSet<String>();

for ( int i = 0; i < noListen; i++ ) {

noListenList.add(sc.next());

}

LinkedList<String> nono = new LinkedList<String>(); 

for ( int i = 0; i < noSee; i++ ) {

String temp = sc.next();

if ( noListenList.contains(temp) ) {

nono.add(temp);

}

}

Collections.sort(nono);

System.out.println(nono.size());

for ( int i = 0; i < nono.size(); i++ ) {

System.out.println(nono.get(i));

}


}


}