현재 시각('시 분')과 요리하는데 걸리는 시간('분')이 주어졌을 때 요리 완료 시간을 return 하면 된다.
처음에는 분 -> 시간 -> 24시 초과 여부에 따른 조치 순으로 계산하려 했으나, 주어진 시각을 분으로 변환하여 계산하는게 편할 것 같았다.
const fs = require('fs');
const path = require('path');
const filePath = process.platform === 'linux' ? '/dev/stdin' : path.join(__dirname, '/example.txt');
const input = fs.readFileSync(filePath).toString().split('\n');
const currentTime = input[0].split(' ');
const currentMin = (+currentTime[0])*60 + (+currentTime[1]);
let finishMin = currentMin + (+input[1]);
while (finishMin >= 1440) {
finishMin -= 1440;
}
console.log(`${parseInt(finishMin/60)} ${finishMin%60}`);
const fs = require("fs");
let input = fs.readFileSync("./dev/stdin").toString().split("\n");
const now = input[0].split(" ").map((item) => +item);
const needTime = +input[1];
function solution(now, needTime) {
let time = [now[0], now[1] + needTime];
if (time[1] >= 60) {
time[0] += Math.floor(time[1] / 60);
time[0] %= 24;
time[1] %= 60;
}
console.log(time.join(" "));
}
solution(now, needTime);