[바미] 베라의 패션
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/15439코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim();const N = parseInt(input, 10);// 서로 다른 색상의 조합 수const result = N * (N - 1);console.log(result);문제 해설주어진 문제는 상의와 하의의 색상이 서로 다른 조합의 가짓수를 구하는 문제입니다. 이 문제는 상의와 하의 각각 N벌이 있고, 상의와 하의의 색상이 모두 다르기 때문에, 서로 다른 색상의 조합을 계산하면 됩니다. 각 상의와 하의의 색상이 다르므로, 총 가능한 조합은 𝑁 × 𝑁이 되는데여기서 같은 색상의 ..
[바미] 덱 2
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/28279코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const N = parseInt(input[0], 10);class Node { constructor(value) { this.value = value; this.next = null; this.prev = null; }}class Deque { constructor() { this.front = null; this.back = null; this.size = 0; ..
[바미] 요세푸스 문제 0
·
하루 알고리즘(JS)
문제 코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split(' ');const N = parseInt(input[0], 10);const K = parseInt(input[1], 10);class Queue { constructor() { this.queue = []; this.front = 0; this.back = 0; } push(x) { this.queue[this.back++] = x; } shift() { if (this.front !== this.back) { const..
[바미] 카드2
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/2164코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim();const N = parseInt(input, 10);class Queue { constructor() { this.queue = []; this.front = 0; this.back = 0; } push(x) { this.queue[this.back++] = x; } shift() { if (this.front !== this.back) { const value = thi..
[바미] 큐 2
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/18258코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const N = parseInt(input[0], 10); // 명령의 수const commands = input.slice(1); // 명령 리스트class Queue { constructor() { this.queue = []; this.frontIndex = 0; this.backIndex = 0; } push(x) { this.queue[this.backIndex++] = x;..
[바미] 도키도키 간식드리미
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/12789 코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const N = parseInt(input[0], 10);const students = input[1].split(' ').map(Number);const stack = [];let next = 1; // 다음으로 간식을 받아야 하는 학생의 번호students.forEach(student => { while (stack.length > 0 && stack[stack.length - 1] === next) { stack.pop(); ..
[바미] 균형잡힌 세상
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/4949코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');// 결과를 저장할 배열const results = [];input.forEach(line => { if (line === '.') return; // 입력의 종료 조건인 '.' 만 단독으로 있는 경우 const stack = []; let balanced = true; for (let char of line) { if (char === '(' || char === '[') { stack.push(char)..
[바미] 괄호
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/9012 코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const T = parseInt(input[0], 10); // 테스트 케이스의 수const results = [];function checkVPS(parenthesis) { const stack = []; for (const char of parenthesis) { if (char === '(') { stack.push(char); // '('를 만나면 스택에 추가 } else if (stack.le..
[바미] 제로
·
하루 알고리즘(JS)
문제https://www.acmicpc.net/problem/10773코드const fs = require('fs');const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const K = parseInt(input[0], 10);const stack = [];for (let i = 1; i acc + curr, 0);// 결과 출력console.log(sum);문제 해설이 문제는 스택을 활용하여 지정된 명령에 따라 숫자를 추가하거나 제거하고, 최종적으로 남은 숫자들의 합을 계산하는 문제입니다.입력된 숫자가 0이면 가장 최근에 입력된 숫자를 삭제하고, 그렇지 않은 경우 입력된 숫자를 스택에 추가해야 하죠. 문제 아래에 힌트가..
Bami