diff --git a/stakbucks/231128/README.md b/stakbucks/231128/README.md new file mode 100644 index 0000000..937352f --- /dev/null +++ b/stakbucks/231128/README.md @@ -0,0 +1,3 @@ +1. [[Lv2] k진수에서 소수 개수 구하기](https://school.programmers.co.kr/learn/courses/30/lessons/92335) +2. [[실버 4] 균형잡힌 세상](https://www.acmicpc.net/problem/4949) +3. [[LV 2] 호텔 대실](https://school.programmers.co.kr/learn/courses/30/lessons/155651) diff --git "a/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/app.js" "b/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/app.js" new file mode 100644 index 0000000..7c1ca6a --- /dev/null +++ "b/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/app.js" @@ -0,0 +1,45 @@ +const fs = require('fs'); +const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; +let input = fs.readFileSync(filePath).toString().trim().split('\n'); + +function solution(input) { + const answer = []; + input.forEach((line) => { + if (line === '.') return; // 입력 종료 조건 + + const stack = []; + + let result = 'yes'; + + for (const letter of line) { + // 여는 괄호는 스택에 넣어준다 + if (letter === '[' || letter === '(') { + stack.push(letter); + } + + // 닫는 괄호는 스택의 top과 비교하여 쌍을 이루는지 체크 + if (letter === ')') { + if (stack.at(-1) !== '(') { + result = 'no'; + break; + } + stack.pop(); + } + if (letter === ']') { + if (stack.at(-1) !== '[') { + result = 'no'; + break; + } + stack.pop(); + } + } + + if (stack.length) result = 'no'; // 괄호가 안닫힌 채로 문자열이 끝나는 경우! + + answer.push(result); + }); + + console.log(answer.join('\n')); +} + +solution(input); diff --git "a/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/input.txt" "b/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/input.txt" new file mode 100644 index 0000000..7a1d3c1 --- /dev/null +++ "b/stakbucks/231128/b_4949_\352\267\240\355\230\225\354\236\241\355\236\214\354\204\270\354\203\201/input.txt" @@ -0,0 +1,8 @@ +So when I die (the [first] I will see in (heaven) is a score list). +[ first in ] ( first out ). +Half Moon tonight (At least it is better than no Moon at all]. +A rope may form )( a trail in a maze. +Help( I[m being held prisoner in a fortune cookie factory)]. +([ (([( [ ] ) ( ) (( ))] )) ]). + . +. \ No newline at end of file diff --git "a/stakbucks/231128/p_155651_\355\230\270\355\205\224\353\214\200\354\213\244.js" "b/stakbucks/231128/p_155651_\355\230\270\355\205\224\353\214\200\354\213\244.js" new file mode 100644 index 0000000..66f6bc4 --- /dev/null +++ "b/stakbucks/231128/p_155651_\355\230\270\355\205\224\353\214\200\354\213\244.js" @@ -0,0 +1,46 @@ +class Hotel { + hotel = new Map(); + + createRoom(endTime) { + this.hotel.set(this.hotel.size, endTime); // (방 번호, 예약 끝나는 시간) + } + + book(startTime, endTime) { + // 예약 가능한 방 찾기 + for (const [number, bookedEndTime] of this.hotel) { + if (addTenMinutes(bookedEndTime) > startTime) continue; + else { + // 예약 가능한 방인 경우 + this.hotel.set(number, endTime); + return; + } + } + // 예약 가능한 방이 없는 경우 + this.createRoom(endTime); + } + + // 방 개수 + getRooms() { + return this.hotel.size; + } +} + +function solution(book_time) { + const hotel = new Hotel(); + book_time.sort().forEach((time) => { + const [startTime, endTime] = time; + hotel.book(startTime, endTime); + }); + return hotel.getRooms(); +} + +// 10분 더해서 "HH:MM" 형식으로 리턴 +function addTenMinutes(time) { + let [hour, min] = time.split(':'); + min = (Number(min) + 10).toString(); + if (min >= 60) { + hour++; + min -= 60; + } + return `${`${hour}`.padStart(2, '0')}:${`${min}`.padStart(2, '0')}`; +} diff --git "a/stakbucks/231128/p_92335_k\354\247\204\354\210\230\354\227\220\354\204\234\354\206\214\354\210\230\352\260\234\354\210\230\352\265\254\355\225\230\352\270\260.js" "b/stakbucks/231128/p_92335_k\354\247\204\354\210\230\354\227\220\354\204\234\354\206\214\354\210\230\352\260\234\354\210\230\352\265\254\355\225\230\352\270\260.js" new file mode 100644 index 0000000..4a704ff --- /dev/null +++ "b/stakbucks/231128/p_92335_k\354\247\204\354\210\230\354\227\220\354\204\234\354\206\214\354\210\230\352\260\234\354\210\230\352\265\254\355\225\230\352\270\260.js" @@ -0,0 +1,33 @@ +function solution(n, k) { + let answer = 0; + const convertedN = n.toString(k); + + let temp = ''; // 0이 나올 때까지 저장 + + for (let i = 0; i < convertedN.length; i++) { + if (convertedN[i] === '0') { + if (temp.length && isPrime(+temp, k)) { + answer++; + } + temp = ''; + } else { + temp += convertedN[i]; + } + } + + // 마지막 남은 temp 처리 + if (temp.length && isPrime(+temp, k)) { + answer++; + } + + // 소수 여부 판별 + function isPrime(n) { + if (n === 1) return false; + for (let i = 2; i <= ~~Math.sqrt(n); i++) { + if (n % i === 0) return false; + } + return true; + } + + return answer; +}