Algorithm


Problem Name: beecrowd | 2003

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

Sunday Morning

 

By Thalyson Nepomuceno, UECE BR Brazil

Timelimit: 1

Sunday is market day. Early in the morning many people move to the Parangaba square where happens a fair, known to be the largest in the city. At the fair the Parangaba you can find everything.

Every Sunday, Bino make purchases at the fair. He always mark with his friend Cino, they met at the bus terminal of Parangaba at 8 am to go together to buy at the fair. But often Bino wake up too late and is late for the meeting with his friend.

Knowing that Bino takes 30-60 minutes to reach the terminal. Tell the maximum delay Bino.

 

Input

 

The input consists of multiple test cases. Each case contains a single line containing a time H (5:00 ≤ H ≤ 9:00) that Bino woken up. The input ends with the final file (EOF).

 

Output

 

For each test case, print "Atraso maximo: X" (without quotes), X indicates the maximum delay (in minutes) of Bino in the encounter with Cino.

 

 

 

Input Sample Output Sample

7:10
5:00

Atraso maximo: 10
Atraso maximo: 0

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void) {
  int a,b,n;
	char aa;
while(scanf("%d %c %d",&a,&aa,&b) != EOF){

	printf("Atraso maximo: ");
	if(a < 7 || (a == 7 && b == 00))
		printf("0\n");
	else
	  	printf("%d\n",(a-7)*60 + b>;
     }
	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7:10 5:00

Output

x
+
cmd
Atraso maximo: 10 Atraso maximo: 0

#2 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char c;
    while(cin >> a >> c >> b)
    {
        int A = a-7;
        int B = b;
        if(A < 0)cout << "Atraso maximo: 0\n";
        else{
            printf("Atraso maximo: %d\n",(A*60)+b>;
        }
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7:10 5:00

#3 Code Example with Javascript Programming

Code - Javascript Programming


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

//// READING FILE | STREAMS ////
class LineReader {
	/**
	 * @param {import("fs").PathLike} path
	 * @param {BufferEncoding} encoding
	 * @return {import("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("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()
		}
	}
}

const calcMaximumDelayTime = (hours, minutes) => (hours >= 7) ? ((hours - 7) * 60) + minutes : 0

async function main() {
	const PATH = "/dev/stdin"
	const ENCODING = "utf8"
	const lineReader = LineReader.create(PATH, ENCODING)

	const helper = (line = "") => line.split(":", 2).map(value => Number.parseInt(value, 10))
	const nextLine = lineReader.nextLine.bind(null, helper)

	const output = []

	while (lineReader.hasNextLine()) {
		const [hour, min] = await nextLine()
		if (Number.isNaN(hour) || Number.isNaN(min)) break // EOF
		output.push(`Atraso maximo: ${calcMaximumDelayTime(hour, min)}`)
	}

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

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

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
7:10 5:00

#4 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        hora = input().split(':')
        n = int(hora[0])*60 + int(hora[1]) - 420
        if n < 0:
            n = 0
        print('Atraso maximo: %d' % n)
        
    except EOFError:
        break
Copy The Code & Try With Live Editor

Input

x
+
cmd
7:10 5:00

Output

x
+
cmd
Atraso maximo: 10 Atraso maximo: 0
Advertisements

Demonstration


Previous
#1987 Beecrowd Online Judge Solution 1987 Divisibility by 3 Solution in C, C++, Java, Js and Python
Next
#2006 Beecrowd Online Judge Solution 2006 Identifying Tea Solution in C, C++, Java, Js and Python