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

 

9012번: 괄호

괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고

www.acmicpc.net

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split("\n");

const N = Number(input.shift());

for(let i = 0 ; i  < N ; i++) {
    const stack = [];
    let prev = '';
    if(input[i].length % 2 !== 0) console.log("NO");
    else {
        const arr = input[i].split("");
        arr.forEach((a, index) => {
           if(index === 0 && a === ')') {
               return false;
           } else {
               if(stack.length === 0) {
                   stack.push(a);
               } else {
                   prev = stack.pop();
                   if(!(prev === '(' && a === ')')) {
                       stack.push(prev);
                       stack.push(a);
                   }
               }
           }
        });
        if(stack.length === 0) console.log('YES');
        else console.log("NO")
    }
}
728x90

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

 

1620번: 나는야 포켓몬 마스터 이다솜

첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면

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));
const dic = {};
const dic1 = {};

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

for(let i = N + 1 ; i < input.length ; i++) {
    if(Number.isNaN(Number(input[i]))) {
        console.log(dic1[input[i]]);
    } else {
        console.log(dic[input[i]]);
    }
}
728x90

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

+ Recent posts