๐ŸŽฒ ๋ฐฑ์ค€ 1874๋ฒˆ ์Šคํƒ ์ˆ˜์—ด

Jeongeunยท2024๋…„ 2์›” 10์ผ
0

๋ฐฑ์ค€

๋ชฉ๋ก ๋ณด๊ธฐ
163/187

๋ฐฑ์ค€ 1874๋ฒˆ

๐Ÿ’Š ๋ฐ˜๋ณต๋ฌธ ํƒˆ์ถœ ์กฐ๊ฑด ์ฃผ์˜! num > n์ผ ๋•Œ๊ฐ€ ์•„๋‹ num > n+1๋กœ ์„ค์ •ํ•ด์ค˜์•ผํ•œ๋‹ค.

์ฝ”๋“œ

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

const answer = [];

const stack = [];
let num = 1;
let index = 0;
while (index < n) {
  if (num > n + 1) return console.log("NO");
  if (stack[stack.length - 1] === input[index]) {
    stack.pop();
    answer.push("-");
    index++;
  } else {
    stack.push(num);
    answer.push("+");
    num++;
  }
}

console.log(answer.join("\n"));

0๊ฐœ์˜ ๋Œ“๊ธ€