JavaScript Algorithm Questions: Game Time

JavaScript Algorithm Questions: Game Time

Read two integers A and B, which represent the start time and end time of the game in hours.

Then please calculate the duration of the game, given that a game can start on one day and end on another, the maximum duration is 24 hours.

If A and B are equal, it is considered to have lasted 24 hours.

input format

A total of one line, containing two integers A and B.

output format

The output format is O JOGO DUROU X HORA(S)where X is the game duration.

data range

0≤A,B≤23

Input sample 1:

16 2

Output sample 1:

O JOGO DUROU 10 HORA(S)

Input sample 2:

0 0

Output sample 2:

O JOGO DUROU 24 HORA(S)

Input sample 3:

2 16

Output sample 3:

O JOGO DUROU 14 HORA(S)
let buf = "";

process.stdin.on("readable", function() {
    
    
    let chunk = process.stdin.read();
    if (chunk) buf += chunk.toString();
});

process.stdin.on("end", function() {
    
    
    let [a, b] = buf.split(' ').map(x => {
    
    return parseInt(x)});

    let res;
    if (a < b) res = b - a;
    else res = 24 - a + b;

    console.log(`O JOGO DUROU ${
      
      res} HORA(S)`);
});

Guess you like

Origin blog.csdn.net/qq_42465670/article/details/130490448
Recommended