Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1561

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

Binary Watch

 

By Gabriel Dalalio, ITA BR Brazil

Timelimit: 1

Some programmers like to be weird and use binary watches like this one in the picture below: 

There are also programmers who like to create questions for online competitions, but don't like to write long and detailed texts in the questions. 

Your task in this problem is to draw the clock image at a given time.

 

Input

 

The input consists of several test cases. Each test case consists of one line containing a time in the format HH:MM (0 ≤ HH < 12 e 0 ≤ MM < 60).

 

Output

 

For each test, the output consists of a clock picture in the time given at the input (the picture should match exactly the format in the examples). Print a blank line after each picture.

 

 

 

Sample Input Sample Output

04:16
07:31
08:32
00:00

 ____________________________________________
|                                            |
|    ____________________________________    |_
|   |                                    |   |_)
|   |   8         4         2         1  |   |
|   |                                    |   |
|   |             o                      |   |
|   |                                    |   |
|   |                                    |   |
|   |         o                          |   |
|   |                                    |   |
|   |   32    16    8     4     2     1  |   |_
|   |____________________________________|   |_)
|                                            |
|____________________________________________|

 ____________________________________________
|                                            |
|    ____________________________________    |_
|   |                                    |   |_)
|   |   8         4         2         1  |   |
|   |                                    |   |
|   |             o         o         o  |   |
|   |                                    |   |
|   |                                    |   |
|   |         o     o     o     o     o  |   |
|   |                                    |   |
|   |   32    16    8     4     2     1  |   |_
|   |____________________________________|   |_)
|                                            |
|____________________________________________|

 ____________________________________________
|                                            |
|    ____________________________________    |_
|   |                                    |   |_)
|   |   8         4         2         1  |   |
|   |                                    |   |
|   |   o                                |   |
|   |                                    |   |
|   |                                    |   |
|   |   o                                |   |
|   |                                    |   |
|   |   32    16    8     4     2     1  |   |_
|   |____________________________________|   |_)
|                                            |
|____________________________________________|

 ____________________________________________
|                                            |
|    ____________________________________    |_
|   |                                    |   |_)
|   |   8         4         2         1  |   |
|   |                                    |   |
|   |                                    |   |
|   |                                    |   |
|   |                                    |   |
|   |                                    |   |
|   |                                    |   |
|   |   32    16    8     4     2     1  |   |_
|   |____________________________________|   |_)
|                                            |
|____________________________________________|

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define MAXV 200100

using namespace std;

typedef vector<int> vi;
typedef pair < int, int> ii;
typedef long long int64;

typedef pair < int, string> is;

int main()
{
    ios::sync_with_stdio(false);
    string s;
    while (cin >> s) {
        char watch[15][70] = {
            { " ____________________________________________" },
            { "|                                            |" },
            { "|    ____________________________________    |_" },
            { "|   |                                    |   |_)" },
            { "|   |   8         4         2         1  |   |" },
            { "|   |                                    |   |" },
            { "|   |   o         o         o         o  |   |" },
            { "|   |                                    |   |" },
            { "|   |                                    |   |" },
            { "|   |   o     o     o     o     o     o  |   |" },
            { "|   |                                    |   |" },
            { "|   |   32    16    8     4     2     1  |   |_" },
            { "|   |____________________________________|   |_)" },
            { "|                                            |" },
            { "|____________________________________________|" }
        };

        int hr = (s[0] - 48) * 10 + (s[1] - 48);
        int min = (s[3] - 48) * 10 + (s[4] - 48);

        if (hr - 8 >= 0)
            hr -= 8;
        else
            watch[6][8] = ' ';

        if (hr - 4 >= 0)
            hr -= 4;
        else
            watch[6][18] = ' ';

        if (hr - 2 >= 0)
            hr -= 2;
        else
            watch[6][28] = ' ';

        if (!hr)
            watch[6][38] = ' ';

        if (min - 32 >= 0)
            min -= 32;
        else
            watch[9][8] = ' ';

        if (min - 16 >= 0)
            min -= 16;
        else
            watch[9][14] = ' ';

        if (min - 8 >= 0)
            min -= 8;
        else
            watch[9][20] = ' ';

        if (min - 4 >= 0)
            min -= 4;
        else
            watch[9][26] = ' ';

        if (min - 2 >= 0)
            min -= 2;
        else
            watch[9][32] = ' ';

        if (!min)
            watch[9][38] = ' ';

        for (int i = 0; i  <  15; i++)
            cout << watch[i] << endl;
        cout << endl;
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
04:16
07:31
08:32
00:00

Output

x
+
cmd
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o o o | | | | | | | | | | | | o o o o o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________| ____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | | | | | | | | | | | | | | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|

#2 Code Example with Python Programming

Code - Python Programming


def printar(h,m):
    h8=h4=h2=m32=m16=m8=m4=m2=0
    h8=h//8
    h%=8
    h4=h//4
    h%=4
    h2=h//2
    h%=2
    m32=m//32
    m%=32
    m16=m//16
    m%=16
    m8=m//8
    m%=8
    m4=m//4
    m%=4
    m2=m//2
    m%=2
    print(" ____________________________________________")
    print("|                                            |")
    print("|    ____________________________________    |_")
    print("|   |                                    |   |_)")
    print("|   |   8         4         2         1  |   |")
    print("|   |                                    |   |")
    print("|   |   ",end="")
    if h8==1:print("o         ",end="")
    else:print("          ",end="")
    if h4==1:print("o         ",end="")
    else:print("          ",end="")
    if h2==1:print("o         ",end="")
    else:print("          ",end="")
    if h==1:print("o  |   |")
    else:print("   |   |")
    print("|   |                                    |   |")
    print("|   |                                    |   |")
    print("|   |   ",end="")
    if m32==1:print("o     ",end="")
    else:print("      ",end="")
    if m16==1:print("o     ",end="")
    else:print("      ",end="")
    if m8==1:print("o     ",end="")
    else:print("      ",end="")
    if m4==1:print("o     ",end="")
    else:print("      ",end="")
    if m2==1:print("o     ",end="")
    else:print("      ",end="")
    if m==1:print("o  |   |")
    else:print("   |   |")

    print("|   |                                    |   |")
    print("|   |   32    16    8     4     2     1  |   |_")
    print("|   |____________________________________|   |_)")
    print("|                                            |")
    print("|____________________________________________|")
    print()

while True:
    try:
        h,m=map(int,input().split(':'))
        printar(h,m)
    except EOFError:break
Copy The Code & Try With Live Editor

Input

x
+
cmd
04:16
07:31
08:32
00:00

Output

x
+
cmd
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o o o | | | | | | | | | | | | o o o o o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________| ____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | | | | | | | | | | | | | | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|

#3 Code Example with Javascript Programming

Code - Javascript Programming


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

/**
 * @param {string} time
 * @description Must have the 00:00 Time Format
*/

function binaryClockMask(time = "00:00") {
	const o = (num = 0, spacing = 1, maskLen = 0) => {
		return Number(num)
			.toString(2)
			.padStart(maskLen, "0")
			.split("")
			.map((d) => (d === "1" ? "o" : " "))
			.join(" ".repeat(spacing))
	}

	const [, hour, min] = time.match(/(\d{1,2}):(\d{1,2})/).map((t) => Number.parseInt(t, 10))

	const BINARY_CLOCK_MASK =
		` ____________________________________________
|                                            |
|    ____________________________________    |_
|   |                                    |   |_)
|   |   8         4         2         1  |   |
|   |                                    |   |
|   |   ${o(hour, 9, 4)}  |   |
|   |                                    |   |
|   |                                    |   |
|   |   ${o(min, 5, 6)}  |   |
|   |                                    |   |
|   |   32    16    8     4     2     1  |   |_
|   |____________________________________|   |_)
|                                            |
|____________________________________________|
`
	return BINARY_CLOCK_MASK
}

function main() {
	const responses = []

	for (const time of input)
		if (time == "") break
		else responses.push(binaryClockMask(time))

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

main()
Copy The Code & Try With Live Editor

Input

x
+
cmd
04:16
07:31
08:32
00:00

Output

x
+
cmd
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o o o | | | | | | | | | | | | o o o o o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________| ____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | o | | | | | | | | | | | | o | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
____________________________________________ | | | ____________________________________ |_ | | | |_) | | 8 4 2 1 | | | | | | | | | | | | | | | | | | | | | | | | | | | | 32 16 8 4 2 1 | |_ | |____________________________________| |_) | | |____________________________________________|
Advertisements

Demonstration


Previous
#1559 Beecrowd Online Judge Solution 1559 2048 Solution in C, C++, Java, Js and Python
Next
#1564 Beecrowd Online Judge Solution 1564 Brazil World Cup Solution in C++, Java, Js and Python