개발자 톡
연습문제 톡
[21년 재직자 대회 예선] 회의실 예약
회의실 반례 부탁드립니다. ;;; ㅜㅜㅜ
- 등록일
- 2023-11-29 16:42:18
- 조회수
- 293
- 작성자
- js9534
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const roomTime = {};
const DASH = '-----';
let [roomNumber, reservationNumber] = [0, 0];
rl.on('line', (input) => {
if (roomNumber === 0 && reservationNumber === 0) {
[roomNumber, reservationNumber] = input.split(' ').map(Number);
} else {
const [name, start, end] = input.split(' ').map((item, index) => {
if (index !== 0) return Number(item);
return item;
});
if (!roomTime[name]){
roomTime[name] = Array.from({ length: 19 }, () => 0);
roomTime[name][18] = 1;
}
else {
for (let i = start; i < end; i += 1) {
roomTime[name][i] = 1;
}
}
}
});
rl.on('close', () => {
const roomNames = Object.keys(roomTime);
roomNames.sort();
const avalible = {};
for (let i = 0; i < roomNames.length; i += 1) {
const times = roomTime[roomNames[i]];
avalible[roomNames[i]] = [];
let current = 1;
let start = 0;
for (let j = 9; j <= 18; j += 1) {
if (times[j] === 0 && current === 1) {
current = 0;
start = j;
} else if (times[j] === 1 && current === 0) {
avalible[roomNames[i]].push([start, j]);
current = 1;
start = 0;
}
}
}
for (let i = 0; i < roomNames.length; i += 1) {
console.log(`Room ${roomNames[i]}:`);
const possible = avalible[roomNames[i]];
if (possible.length > 0) console.log(`${possible.length} available:`);
else {
console.log('Not available');
console.log(DASH);
continue;
}
for (let j = 0; j < possible.length; j += 1) {
console.log(`${String(possible[j][0]).padStart(2, 0)}-${possible[j][1]}`);
}
if (i < roomNames.length - 1) console.log(DASH);
}
process.exit();
});
#[21년_재직자_대회_예선]_회의실_예약
#javascript
#node