본문 바로가기

BAEKJOON/JavaScript

[BAEKJOON] 인공지능 시계 (2530번)

// const input  = require("fs").readFileSync("/dev/stdin").toString().trim().split("\n");
const input  = require("fs").readFileSync("testCase/testCase.txt").toString().trim().split("\n");

function aiTimer(input) {
    let hour = parseInt(input[0].split(" ")[0]);
    let min  = parseInt(input[0].split(" ")[1]);
    let sec  = parseInt(input[0].split(" ")[2]);
    let cookingTime = parseInt(input[1]);
    let totalSec = hour * 3600 + min * 60 + sec + cookingTime;

    secToTime(totalSec);
}

function secToTime(totalSec) {
    let hour = parseInt(totalSec / 3600);
    let min  = parseInt((totalSec % 3600) / 60);
    let seconds = totalSec % 60;

    if(hour === 24) {
        hour = 0; 
    } else if(hour > 24) {
        hour = hour % 24;
    }

    return console.log(hour + " " + min + " " + seconds);
}

aiTimer(input);

'BAEKJOON > JavaScript' 카테고리의 다른 글

[BAEKJOON] 시험 점수 (5596번)  (0) 2022.05.20
[BAEKJOON] 숫자카드2 (10816번)  (0) 2022.05.06
[BAEKJOON] 블랙잭 (2798번)  (0) 2022.04.27
[BAEKJOON] 나이순 정렬 (10814번)  (0) 2022.04.26
[BAEKJOON] 이항 계수1 (11050번)  (0) 2022.04.22