Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

The map

After going through the door, you find yourselves in a chamber of the secret terrorist base. From this room there are doors which lead to new rooms, which also has doors...
Luckily someone carved a map to the wall, so your task is to try to determine the location of the "main chamber" of the terrorists.

Input

The input consists of 8 lines, each terminated by an end of line character. In each of the lines there are exactly 8 characters, separated by a single space character (so 8 characters + the separating spaces + the end of line character). The characters are the following:

  • Exactly one "p" character which tells us our current position.
  • An arbitrary number of "m", "u" and "~" characters (for a total of 63 characters). The "u" character denotes a room where the terrorist leaders have a hgh probability to appear. The "m" character denotes a room where they have a low probability to appear and the "~" character denotes an empty room.
  • There is at least one "u" or "m" on the field.
Note: the indexing of this 8x8 matrix goes by the regular "the first character of the first line is the [0][0] index and the last character of the last line is the [7][7] index" principle.

Output

The output is a single line which contains the coordinate(s) in the form [row,column] of the fields which you "forcefully enter" based on the below rules in the hope that you find the terrorist leaders there. If there are more than one fields like this, then list all and separate them with a single space character and order them first by the row index and secondly by the column index. (E.g. [1,3] [3,2] [3,4] [3,7] [5,1])

Rules

  • If there is at least one "u" field on the map, then the terrorist leaders are surely in one of these "u" fields. So in this case the "m" fields can be considered empty.
  • If there are no "u" fields on the map, then the terrorist leaders are surely in an "m" field.
  • The terrorist leaders are never hiding in an "~" field.
  • You may only move up-down and left-right. Moving one index means a distance of 1 unit. So e.g. if you need to move down 3 indices, then move to the right 4, then it means a 7 unit distance.
  • In compliance with the above rules, your "target" is always residing in the closest field to your initial position.
  • If more than one potential rooms lie at the same distance from your starting point, then the leaders are occupying each. In this and only this case will you have more than one coordinate-pairs in your output.

Example

Input:
  1. p ~ ~ ~ ~ ~ ~ ~
  2. ~ u ~ m ~ ~ ~ ~
  3. u ~ ~ ~ ~ ~ ~ ~
  4. ~ ~ ~ ~ ~ ~ ~ ~
  5. ~ ~ ~ ~ ~ m ~ ~
  6. ~ ~ ~ ~ ~ ~ ~ ~
  7. ~ ~ ~ m ~ ~ ~ ~
  8. ~ ~ ~ ~ ~ ~ ~ ~
download as text file Output:
  1. [1,1] [2,0]
download as text file Input:
  1. ~ ~ ~ p ~ ~ ~ ~
  2. ~ ~ ~ ~ ~ ~ ~ ~
  3. ~ ~ ~ ~ ~ ~ ~ ~
  4. ~ ~ m ~ ~ ~ ~ ~
  5. ~ ~ ~ ~ u ~ ~ ~
  6. ~ ~ ~ ~ ~ ~ ~ ~
  7. ~ ~ ~ ~ ~ u ~ ~
  8. ~ ~ ~ ~ ~ ~ ~ ~
download as text file Output:
  1. [4,4]
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024