Algorithm


Problem Name: beecrowd | 2685

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

The Change

 

By Samuel Lucas Santos Gomes, IFSULDEMINAS BR Brazil

Timelimit: 1

Julio is creating a new SmartWatch, especially for programmers. It's amazing the advantages he offers and the comfort that he has to code. The clock still been in development and he promised to fix the bugs and put some better gear and, in return, he asked for a simple system for Stand Bay mode. The problem is the clock itself always has the inclination angle of the Sun/Moon (0 to 360). Given a clock, your mission is, if you want to accept: given in degrees the inclination of the Sun/Moon in relation to the Earth, tell what period of the day it is.

 

Input

 

The input contains an integer M (0 ≤ M ≤ 360) representing the degree of the Sun/Moon. As the position changes constantly, your program will receive several cases every second (EOF).

 

Output

 

Print a greeting for the time of day it is: "Boa Tarde!!"(Good Afternoon!!), "Boa Noite!!"(Good Night!!), "Bom Dia!!"(Good Morning) and "De Madrugada!!"(Dawn!!).

 

 

 

Input Sample Output Sample

0
45
360
90
180

Bom Dia!!
Bom Dia!!
Bom Dia!!
Boa Tarde!!
Boa Noite!!

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int n;

    while (scanf("%i", &n) != EOF)
    {
        if (n < 90 || n==360)
            printf("Bom Dia!!\n");

        else if (n < 180)
            printf("Boa Tarde!!\n");

        else if (n  <  270)
            printf("Boa Noite!!\n");

        else if (n<360)
            printf("De Madrugada!!\n");
    }

    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
0 45 360 90 180

Output

x
+
cmd
Bom Dia!! Bom Dia!! Bom Dia!! Boa Tarde!! Boa Noite!!

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;
int main(){
    int m;
while(cin >> m){
    if (m >= 0 and m  <  90 or m == 360) {
        cout << "Bom Dia!!" << endl;
    }else if (m >= 90 and m  <  180) {
        cout << "Boa Tarde!!" << endl;
    }else if (m >= 180 and m  <  270) {
        cout << "Boa Noite!!" << endl;
    }else {
        cout << "De Madrugada!!" << endl;
    }
}
return 0;    
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
0 45 360 90 180

Output

x
+
cmd
Bom Dia!! Bom Dia!! Bom Dia!! Boa Tarde!! Boa Noite!!

#3 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        n = int(input())
        if ((n >= 0 and n < 90) or n == 360):
            print('Bom Dia!!')
        elif (n >=90 and n < 180):
            print('Boa Tarde!!')
        elif (n >= 180 and n < 270):
            print('Boa Noite!!')
        elif (n >= 270 and n < 360):
            print('De Madrugada!!')

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

Input

x
+
cmd
0 45 360 90 180

Output

x
+
cmd
Bom Dia!! Bom Dia!! Bom Dia!! Boa Tarde!! Boa Noite!!

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { createReadStream } = require("node:fs")
const { createInterface } = require("node:readline")

//// READING FILE | STREAMS ////

class LineReader {
	/**
	 * @param {import("node:fs").PathLike} path
	 * @param {BufferEncoding} encoding
	 * @return {import("node:readline").ReadLine}
	 */
	static createReadLineInterface(path, encoding = "utf8") {
		const readStreamOptions = {
			encoding: encoding,
			flags: "r",
			emitClose: true,
			autoClose: true
		}

		return createInterface({
			input: createReadStream(path, readStreamOptions),
			crlfDelay: Infinity,
			terminal: false
		})
	}

	/**
	 * @param {import("node:fs").PathLike} path
	 * @param {BufferEncoding} encoding
	 */
	static create(path, encoding) {
		const RLI = LineReader.createReadLineInterface(path, encoding)

		let EOF = false

		const nextLineGenerator = (async function* () {
			for await (const line of RLI)
				yield line
		})()

		RLI.once("close", () => { EOF = true })

		return {
			hasNextLine: () => !EOF,
			nextLine: async (/** @type {unknown} */ fn) => {
				const { value } = (await nextLineGenerator.next())
				return (typeof fn === "function") ? fn(value) : value
			},
			close: () => RLI.close()
		}
	}
}

//// MAIN  ////

async function main() {
	const PATH = "/dev/stdin"
	const ENCODING = "utf8"

	const output = []
	const lineReader = LineReader.create(PATH, ENCODING)

	while (lineReader.hasNextLine()) {
		const angle = Number.parseInt(await lineReader.nextLine(), 10) % 360
		if (Number.isNaN(angle)) break /// EOFile Condition

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

	if (lineReader.hasNextLine())
		lineReader.close()

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

main()

Copy The Code & Try With Live Editor

Input

x
+
cmd
0 45 360 90 180

Output

x
+
cmd
Bom Dia!! Bom Dia!! Bom Dia!! Boa Tarde!! Boa Noite!!
Advertisements

Demonstration


Previous
#2682 Beecrowd Online Judge Solution 2682 Fault Detector Solution in C, C++, Java, Js and Python
Next
#2686 Beecrowd Online Judge Solution 2686 The Change Continues!! Solution in C, C++, Java, Js and Python