[10250] ACMํ˜ธํ…” _ node.js

๋ฐ•์„œํ˜„ยท2023๋…„ 8์›” 4์ผ
0
post-thumbnail

๐Ÿ10250_ACMํ˜ธํ…”


๐Ÿ”ปH = 6์ผ๊ฒฝ์šฐ ์˜ˆ์‹œ ๊ทธ๋ฆผ

  1. ์ž…๋ ฅ๊ฐ’ txtํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

๐Ÿ”ป10250.txt

2
6 12 10
30 50 72
  1. ์ž…๋ ฅ๊ฐ’ ๋ถˆ๋Ÿฌ์˜ค๋Š” mainํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

๐Ÿ”ปVScode

function main () {
    // let input = require('fs').readFileSync('/dev/stdin').toString().split('\n');
    let input = require('fs').readFileSync('txt/10250.txt').toString().split('\n');
    let data = +input[0];

    for (let i = 1; i <= data; i++) {
        const [hotelFloors, hotelRooms, guest] = input[i].split(' ').map(Number);
        const roomNumber = findRoomNumber(hotelFloors, hotelRooms, guest);
        console.log(roomNumber);
    }
}

main();
โ–ช ์ฃผ์„์ฒ˜๋ฆฌ ๋œ ๋ถ€๋ถ„์€ ๋ฐฑ์ค€์— ์ œ์ถœํ•  ๋•Œ ์‚ฌ์šฉ
  ์ฃผ์„์˜ ์•„๋ž˜๋ถ€๋ถ„์€ ์ œ์ถœ ์ „ vscode๋กœ ํ™•์ธํ•  ๋•Œ ์‚ฌ์šฉ
  
โ–ช let T = +input[0]
  ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’์„ ์ˆซ์žํ˜•์œผ๋กœ ๋ณ€ํ™˜
  
โ–ช for ๋ฐ˜๋ณต๋ฌธ
  T๊ฐœ๋งŒํผ์˜ ์ž…๋ ฅ๊ฐ’์ด ์žˆ์œผ๋ฏ€๋กœ T๋ฒˆ ๋ฐ˜๋ณต
  1. ๋ฐฉ๋ฒˆํ˜ธ ์ฐพ๋Š” findRoomNumber ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ

๐Ÿ”ปVScode

function findRoomNumber(hotelFloors, hotelRooms, guest) {
    let room = Math.ceil(guest / hotelFloors);
    let floor = guest % hotelFloors === 0 ? hotelFloors : guest % hotelFloors;
    // console.log(`rooom : ${room}`);
    // console.log(`floor : ${floor}`);
    room = room.toString().padStart(2, '0')
    return `${floor}${room}`
}
โ–ช room = room.toString().padStart(2, '0')
  ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๊ฐ€ 2๊ฐ€ ๋  ๋•Œ ๊นŒ์ง€ ์•ž์— '0'์„ ๋ถ™์ธ๋‹ค
  1 -> 01, &nbsp &nbsp &nbsp 10 -> 10

0๊ฐœ์˜ ๋Œ“๊ธ€