ENIGMA-0x02 (2024) - S0 (The Treasure Key)

View as PDF

Submit solution

Points: 100 (partial)
Time limit: 1.0s
Memory limit: 16M

Authors:
Problem types
Allowed languages
Blockly, C, C++, Java, Pascal, Python

The Treasure Key

Annoula and her brother Totos, while searching in the attic of their house for some old photo albums, discovered a forgotten chest. Inside the chest, there is an old map that once belonged to the legendary pirate Henry Every. According to the map, a precious treasure is hidden somewhere on the island, but to reach it, they must solve three puzzles.

Annoula and Totos are curious to see what the chest contains. However, they must first open the lock.

Puzzle 1

At the bottom of the chest, there are two numbers engraved. Next to these numbers, the pirate had also engraved a note:
«1. My crew consists of as many sailors as the product of the two numbers engraved here. If you manage to find the product and enter the number in the lock, the chest will open!»

Puzzle 2

A little further down, it says:
«2. Once you open the chest, you only need to find where the treasure is hidden on the map. From the numbers A and B, either A, B, or both A and B might be 0.
However, it's possible that neither of them is 0.

  • If neither is 0, the treasure is hidden under the number 0 on the map,
  • If only A is 0, the treasure is hidden under the number 1 on the map,
  • If only B is 0, the treasure is hidden under the number 2 on the map,
  • If both A and B are 0, the treasure is hidden under the number 3 on the map»

Totos and Annoula need your help because they're quite stressed and need to verify that they're doing the right calculations to eventually find the treasure!

We want to write a program that reads from input STDIN two integers, A and B (both positive, single-digit numbers), separated by a newline character ('\n'), and prints two lines in the output STDOUT.
In the first line, the program should print the product M of A and B.
In the second line, the program should print one of the numbers 0, 1, 2, or 3 based on the pirate's note 2.

Examples
1st

Input (STDIN)

6
8

Output (STDOUT)

48
0
Explanation of the first example:

The crew of the captain consists of 6 * 8 = 48 sailors, and neither of the two numbers is 0, so the output is 0.

2nd

Input (STDIN)

0
3

Output (STDOUT)

0
1
Explanation of the second example:

The crew of the captain consists of 0 * 3 = 0 sailors, and the first number, A, is 0, so the output is 1.

Note! Each line of input and output (should) end with a newline character '\n'.

Here is the translation of the last part:


A Little Cheat Sheet!

Python:

from sys import exit

# The execution of the program starts here!
if __name__ == "__main__":
    x = int(input())

    if(x == 1) : ...
    elif(x == 2) : ...

    exit(0)

C/C++ (με cstdio):

#include <stdio.h>

// The execution of the program starts here!
int main() {
    int x;
    scanf("%d", &x);

    if(x == 1){...}
    else if(x == 2){...}

    return 0;
}

C++ (με iostream):

#include <iostream>

// The execution of the program starts here!
int main() {
    int x;
    std::cin >> x; // Use std::cin for input

    if (x == 1) {
        // Add your code for x == 1 here
    } else if (x == 2) {
        // Add your code for x == 2 here
    }

    return 0;
}

Comments

There are no comments at the moment.