Algorithm
Problem Name: beecrowd | 3084
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/3084
Old Clock
By Guilherme Londe, PUC Goiás Brazil
Timelimit: 1
Ezequiel have an old and valuable clock, but some of its characteristics got lost over time. The pointers still marks the hours and minutes correctly, but the markers and numbers became unreadable.
Ezequiel uses an auxiliary instrument to observe the angles formed by the hour and minute pointers. He asks you to help writing a program that indicates the hour and the minute at the moment of measurement. You must consider that both angles measured at the time 00:00 are equal to zero and both pointers only moves when a corresponding time unit (hour or minute) is completed.
Input
The input consists of several test cases and is finished by the end-of-file (EOF). Each line is a new test case and have two integers h and m (0 ≤ h, m < 360) that are, respectively, the angles measured on the hour and minute pointers.
Output
For each test case output one line with the values of the hour and minute in the format “hh:mm” (without quotes), as seen in the examples.
Input Sample | Output Sample |
240 132 |
08:22 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(int argc, char **argv)
{
unsigned a, b;
while (~scanf("%u %u", &a, &b))
printf("%02u:%02u\n", (a / 30U), (b / 6U));
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const input = readFileSync("/dev/stdin", "utf8").split("\n").map(lines => lines.split(" "))
const { format } = new Intl.NumberFormat("en-US", {
useGrouping: false,
minimumIntegerDigits: 2,
style: "decimal",
})
const FULL_BACK_ANGLE = 360
const HOUR_ANGLE = FULL_BACK_ANGLE / 12
const MINUTE_ANGLE = FULL_BACK_ANGLE / 60
function main() {
const responses = []
for (const [H, M] of input) {
if (H == "" || M == "") break // EOFile Condition
const hours = (+H % FULL_BACK_ANGLE) / HOUR_ANGLE
const minutes = (+M % FULL_BACK_ANGLE) / MINUTE_ANGLE
responses.push(`${format(hours)}:${format(minutes)}`)
}
console.log(responses.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
Output