https://www.acmicpc.net/problem/1408

const [current, start] = require("fs")
  .readFileSync("/dev/stdin")
  .toString()
  .split("\n");

const [currentClock, currentMin, currentSec] = current
  .split(":")
  .map((num) => parseInt(num));

let [startClock, startMin, startSec] = start
  .split(":")
  .map((num) => parseInt(num));

let remainingClock = 0;
let remainingMin = 0;
let remainingSec = 0;

const ONE_MINIUTE = 60;
const Clock_OF_DAY = 24;

startClock = currentClock > startClock ? startClock + Clock_OF_DAY : startClock;

if (startSec - currentSec < 0) {
  remainingSec = ONE_MINIUTE + startSec - currentSec;
  --startMin;
} else {
  remainingSec = startSec - currentSec;
}

if (startMin - currentMin < 0) {
  remainingMin = ONE_MINIUTE + startMin - currentMin;
  --startClock;
} else {
  remainingMin = startMin - currentMin;
}

remainingClock = startClock - currentClock;

const result = [remainingClock, remainingMin, remainingSec].map((item) =>
  item < 10 ? `0${item}` : `${item}`
);

console.log(result.join(":"));

+ Recent posts