Title:
Sometimes people use four digits to represent a time. For example, 1106 means 11:06. Now, your program calculates the end time based on the start time and the elapsed time.
Read in two numbers. The first number represents the current time with such four digits, and the second number represents the minutes. Calculate the time after so many minutes, and the result is also expressed as four digits. When the hour is a single digit, there is no leading zero, for example, 5:30 is 530; 0:30 means 030. Note that the second number may represent more than 60 minutes or a negative number.
Input format:
Input gives two integers in one line, which are the starting time represented by four digits and the elapsed minutes, separated by spaces. Note: in the starting time, when the hour is a single digit, there is no leading zero, that is, 5:30 is 530; 0:30 means 030. The number of minutes passed may be more than 60 or negative.
Output format:
Output the termination time represented by four digits. When the hour is a single digit, there is no leading zero. The title shall be guaranteed to start and end on the same day.
Input sample:
1120 110 |
Output example:
1310 |
Javascript code:
const { parse } = require('path')
var readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.on('line', function(line) {
var tokens = line. Split ("") // space delimited strings as string arrays
var m = parseInt(tokens[0])
var n = parseInt(tokens[1])
var ret = time(m,n)
console.log(ret)
})
function time(m,n){
var a1 = m % 100
var a2 = (m - a1) / 100
Var begin = A2 * 60 + A1 // starting minutes
Var final = n + begin // termination minutes
Var min = final% 60 // termination minutes
Var hour = (final - min) / 60 // termination hours
if(hour != 0){
s = hour * 100 + min
} else{
var str1 = hour.toString()
var str2 = min.toString()
s = str1 + str2
}
return s
}