-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]. | ||
([ (([( [ ] ) ( ) (( ))] )) ]). | ||
. | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |