ENIGMA-0x00 (2022) - S0 (Cheating)

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 16M

Authors:
Problem types
Allowed languages
Blockly, C, C#, C++, Fortran, Go, Haskell, Java, Lua, Pascal, Perl, PHP, Python
Αντιγραφή

It is Sunday morning and Totos is stressed:

"ENIGMA begins in a few moments and I can't remember any programming language!"

Luckily his friend Annoula, who is the best at programming, is sitting next to him and intends to help him :).

The competition begins and within minutes, Annoula solves the first problem, writes it down on a piece of paper and hands it to him to copy. She even wrote it in two of the most popular programming languages, C and Python so that he has options to choose from!
Totos immediately starts copying, but luckily, just before he hits the submit button, he realizes that something is not right.
The questions are different for each child!

He was asked the following:

"We want to write a program that reads from the input STDIN three positive integers N, S and T, and prints to the output STDOUT sets of characters '@' or spaces ' ' and '\n'.

  • N (1 \le N \le 10) denotes the number of pieces of paper.
  • S (1 \le S \le 10) denotes the size of the pieces of paper.
  • T (0 \le T \le 1) denotes the way of positioning the pieces of paper, 0 for horizontal, 1 for vertical.

Attention! Each input or output line should end with the line change character '\n'.

Examples
1st

STDIN

4 3 0

STDOUT

@@@ @@@ @@@ @@@
@@@ @@@ @@@ @@@
@@@ @@@ @@@ @@@
2nd

STDIN

2 4 1

STDOUT

@@@@
@@@@
@@@@
@@@@

@@@@
@@@@
@@@@
@@@@
The following is the cheat sheet ;)
#include <stdio.h>

// read_number(), STDIN: "123 "
// |123  :   0
// 1|23  :   0 * 10 + 1 =   1
// 12|3  :   1 * 10 + 2 =  12
// 123|  :  12 * 10 + 3 = 123
// 123 | : 123
int read_number() {
    int number = 0;

    char c = getchar();
    // Χτίζω τον αριθμό
    while((c >= '0') && (c <= '9')) {
        int digit = c - '0';
        number = number * 10 + digit;
        c = getchar();
    }

    return number;
}

// squares_horizontal(2, 3)
// @@@ @@@
// @@@ @@@
// @@@ @@@
void squares_horizontal(int cnt, int size) {
    // Screen lines counter
    for(int i = 0; i < size; i++) {

        // Squares counter
        for(int j = 0; j < cnt; j++) {

            // Characters counter
            for(int k = 0; k < size; k++) {
                putchar('@');
            }

            putchar(' ');
        }

        putchar('\n');
    }
}

// squares_vertical(2, 3)
// @@@
// @@@
// @@@
//
// @@@
// @@@
// @@@
void squares_vertical(int cnt, int size) {
    // Squares counter
    for(int j = 0; j < cnt; j++) {

        // Screen lines counter
        for(int i = 0; i < size; i++) {

            // Characters counter
            for(int k = 0; k < size; k++) {
                putchar('@');
            }

            putchar('\n');
        }

        putchar('\n');
    }
}

// The execution of the program starts here!
int main() {
    int cnt = read_number();
    int size = read_number();

    squares_horizontal(cnt, size);
    squares_vertical(cnt, size);

    return 0;
}
from sys import stdin, stdout, exit

# read_number(), STDIN: "123 "
# |123  :   0
# 1|23  :   0 * 10 + 1 =   1
# 12|3  :   1 * 10 + 2 =  12
# 123|  :  12 * 10 + 3 = 123
# 123 | : 123
def read_number():
    number = 0

    c = stdin.read(1)
    # Χτίζω τον αριθμό
    while((c >= '0') and (c <= '9')):
        digit = int(c)
        number = number * 10 + digit
        c = stdin.read(1)

    return number



# squares_horizontal(2, 3)
# @@@ @@@
# @@@ @@@
# @@@ @@@
def squares_horizontal(cnt, size):
    # Μετρητής γραμμών οθόνης
    for i in range(0, size, 1):

        # Μετρητής τετραγώνων
        for j in range(0, cnt, 1):

            # Μετρητής χαρακτήρων
            for k in range(0, size, 1):
                stdout.write('@')

            stdout.write(' ')

        stdout.write('\n')





# squares_vertical(2, 3)
# @@@
# @@@
# @@@
#
# @@@
# @@@
# @@@
def squares_vertical(cnt, size):
    # Μετρητής τετραγώνων
    for j in range(0, cnt, 1):

        # Μετρητής γραμμών οθόνης
        for i in range(0, size, 1):

            # Μετρητής χαρακτήρων
            for k in range(0, size, 1):
                stdout.write('@')

            stdout.write('\n')

        stdout.write('\n')





# Η εκτέλεση του προγράμματος ξεκινά εδώ!
if __name__ == "__main__":
    cnt = read_number()
    size = read_number()

    squares_horizontal(cnt, size)
    squares_vertical(cnt, size)

    exit(0)

Comments

There are no comments at the moment.