[Softeer, JS] 근무 시간

mxxn·2023년 7월 24일

Softeer

목록 보기
2/8

문제

문제 링크 : 근무 시간

풀이

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

let sum = 0

rl.on('line', input => {
    let [timeA, timeB] = input.split(' ').map(el => el.split(':'))
    sum += (+timeB[0]*60 + +timeB[1]) - (+timeA[0]*60 + +timeA[1])
})

rl.on('close', () => {
    console.log(sum)
})
  • 출근시간을 timeA, 퇴근시간을 timeB로 하고 시와 분을 쪼개어 할당
  • 시간에는 60을 곱하고 분은 그냥 더하여 timeB에서 timeA를 빼는 것으로 sum 계산
profile
내일도 글쓰기

0개의 댓글