Skip to content

Commit

Permalink
231128 풀이 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
stakbucks committed Nov 27, 2023
1 parent 24bbba8 commit 07b78ef
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stakbucks/231128/README.md
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 45 additions & 0 deletions stakbucks/231128/b_4949_균형잡힌세상/app.js
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 8 additions & 0 deletions stakbucks/231128/b_4949_균형잡힌세상/input.txt
Original file line number Diff line number Diff line change
@@ -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)].
([ (([( [ ] ) ( ) (( ))] )) ]).
.
.
46 changes: 46 additions & 0 deletions stakbucks/231128/p_155651_호텔대실.js
Original file line number Diff line number Diff line change
@@ -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')}`;
}
33 changes: 33 additions & 0 deletions stakbucks/231128/p_92335_k진수에서소수개수구하기.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 07b78ef

Please sign in to comment.