Algorithm


Problem Name: beecrowd | 2686

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2686

The Change Continues!!

 

By Samuel Lucas Santos Gomes, IFSULDEMINAS BR Brazil

Timelimit: 1

Again Julius asks for your help, he has forgotten a small detail. As his previous program only reported a greeting, he asked him to turn the Sun / Moon degree into HH: MM: SS. Then if you accept: given a degree relative to the position of the Sun / Moon, redo the system only now that beyond the salutation of each period of the day, accurately report the hours, minutes and seconds.

 

Input

 

The input contains a floating point M (0 ≥ M <360) representing the position, in degrees, of the Sun/Moon relative to the ground. As they walk in constant motion their program will receive several cases every second(EOF).

 

Output

 

Print out what time of day it is: "Boa Tarde!!"(Good Afternoon!!), "Boa Noite!!"(Good Night!!), "Bom Dia!!"(Good Morning!!) and "Boa Madrugada!!"(Good Dawn!!) and on the bottom lines display the hours, minutes and seconds (HH: MM: SS).

 

 

 

Input Sample Output Sample

1.50
95.5
187.5
279.5

Bom Dia!!
06:06:00
Boa Tarde!!
12:22:00
Boa Noite!!
18:30:00
De Madrugada!!
00:38:00

 

Code Examples

#1 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8")
	.split("\n")
	.map(Number.parseFloat)

const TIME_UNITS = {
	get MILLISECOND() { return 1 },
	get SECOND() { return 1000 * this.MILLISECOND },
	get MINUTE() { return 60 * this.SECOND },
	get HOUR() { return 60 * this.MINUTE },
	get DAY() { return 24 * this.HOUR },
	//...
}

function formatTimeDurationToParts(duration = 0) {
	const hours = Math.floor(duration / 3600)
	const minutes = Math.floor(duration / 60) % 60
	const seconds = duration % 60

	return [hours, minutes, seconds]
}

function main() {
	const output = []

	for (let angle of input) {
		if (Number.isNaN(angle)) break // EOF

		angle %= 360

		if (0 <= angle && angle < 90) output.push("Bom Dia!!")
		else if (90 <= angle && angle < 180) output.push("Boa Tarde!!")
		else if (180 <= angle && angle < 270) output.push("Boa Noite!!")
		else if (270 <= angle && angle < 360) output.push("De Madrugada!!")

		output.push(
			formatTimeDurationToParts(Math.round(((angle + 90) % 360) / 360 * (TIME_UNITS.DAY / TIME_UNITS.SECOND)))
				.map(t => t.toString(10).padStart(2, "0"))
				.join(":")
		)
	}

	console.log(output.join("\n"))
}

main()

Copy The Code & Try With Live Editor

#2 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        m = float(input())
        mensagem = ''
        m *= 86400
        hora = m/3600
        m = float(m % 3600)
        minuto = m/60
        m = int(m % 60)
        print(hora, minuto, m)

    except EOFError:
        break
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
#2685 Beecrowd Online Judge Solution 2685 The Change Solution in C, C++, Java, Js and Python
Next
#2702 Beecrowd Online Judge Solution 2702 Hard Choice Solution in C, C++, Java, Js and Python