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

+ Recent posts