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

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

 

1269번: 대칭 차집합

첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어

www.acmicpc.net

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

let A = {};
input[1].split(" ").forEach(a => A[a] = 1);

let B = {};
input[2].split(" ").forEach(b => B[b] = 1);

// A - B
input[2].split(" ").forEach(b => {
    if(A[b] !== undefined) A[b]--;
});

const keyA = Object.keys(A);

for(let i =  0 ; i < N ; i++) {
    if(A[keyA[i]] === 1) result += 1;
}

// B - A
input[1].split(" ").forEach(a => {
    if(B[a] !== undefined) B[a]--;
});

const keyB = Object.keys(B);
for(let i =  0 ; i < M ; i++) {
    if(B[keyB[i]] === 1) result += 1;
}

console.log(result);
728x90

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

 

10816번: 숫자 카드 2

첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");
const dic = {};
const N = Number(input[0]);
const M = Number(input[2]);
const sang = input[1].split(" ");
const comp = input[3].split(" ");
const answer = [];


sang.forEach(d => {
    if(dic[d] === undefined) dic[d] = 1;
    else dic[d] ++;
});

comp.forEach((d) => {
    if(dic[d] !== undefined ) answer.push(dic[d]);
    else answer.push(0);
})

console.log(answer.join(" "));
728x90

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

 

10815번: 숫자 카드

첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split("\n");
const dic = {};
const N = Number(input[0]);
const M = Number(input[2]);
const sang = input[1].split(" ");
const comp = input[3].split(" ");
const answer = [];


sang.forEach(c => {
    dic[c] = 0;
});

comp.forEach((d) => {
    if(dic[d] !== undefined ) answer.push(1);
    else answer.push(0);
})

console.log(answer.join(" "));
728x90

+ Recent posts