-
[백준 / javascript] 4949번 균형잡힌 세상알고리즘 2023. 4. 4. 03:17728x90
https://www.acmicpc.net/problem/4949
const readFile = process.platform === 'linux' ? '/dev/stdin' : 't.txt'; const input = require('fs') .readFileSync(readFile) .toString() .trim() .split('\\n'); const open = ['(', '[']; const close = [')', ']']; let stack; const answer = []; input.slice(0, input.length - 1).forEach((v) => { let check = false; stack = []; for (let i = 0; i < v.length; i++) { if (open.includes(v[i])) { stack.push(v[i]); } else if (close.includes(v[i])) { if (stack.pop() !== open[close.indexOf(v[i])]) { answer.push('no'); check = true; break; } } } if (!check) { if (stack.length === 0) { answer.push('yes'); } else { answer.push('no'); } } }); console.log(answer.join('\\n'));
728x90'알고리즘' 카테고리의 다른 글
[백준 / javascript] 1021번 회전하는 큐 (0) 2023.04.10 [백준 / javascript] 1065번 한수 (0) 2023.04.10 [백준 / javascript] 25325번 학생 인기도 측정 (0) 2023.03.31 [백준 / javascript] 2816번 디지털 티비 (0) 2023.03.29 [백준 / javascript] 13458번 시험감독 (1) 2023.03.29