문제
입력값
코드
const fs = require('fs');//백준 제출용
// const input = fs.readFileSync("/dev/stdin").toString().split('\n');//문제풀이용
const input = fs.readFileSync('example.txt').toString().split('\n');let a = parseInt(input[0].split(' ')[0]);
let b = parseInt(input[0].split(' ')[1]);
let c = parseInt(input[1]);let h = 0;
let m = 0;h = Math.floor((a 60 + b + c) / 60);
m = (a 60 + b + c) % 60;
if (h >= 24) {
h -= 24;
}
console.log ${h} ${m});
출력
문제 해결방법
- 주어진 숫자와 같거나 작은 정수 중에서 가장 큰 수를 반환하는 역할을 하는 Math 객체 안에있는 floor메소드를 사용해서 시간을 출력했습니다.
- 모두 분으로 변경하여 더해준다.
- 더한 값에서 60을 나눠서 몫을 시간, 나머지를 분으로 출력
- 시간이 24가 넘을 경우 -24를 해준 후 출력