https://www.acmicpc.net/problem/1764

 

1764번: 듣보잡

첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다.

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");
const [N, M] = input[0].split(" ").map(d => Number(d));
const dic = {};
const answer = [];

for(let i = 1 ; i <= N ; i++) {
    dic[input[i]] = 1;
}

for(let i = N+1; i < input.length ; i++) {
    if(dic[input[i]] !== undefined) answer.push(input[i]);
}

console.log(answer.length);
answer.sort(function(a,b) {
    if(a>b) return 1;
    else if( a < b ) return -1;
    return 0;});

answer.forEach((a) => {
    console.log(a);
});
728x90

+ Recent posts