Mathematical and Physical Journal
for High Schools
Issued by the MATFUND Foundation
Already signed up?
New to KöMaL?

Problem I. 343. (March 2014)

I. 343. We are given an N×N (1\leN\le50) board. Each cell of the board is either empty or has some color. When the board is in its vertical position, the colored squares try to occupy the lowest possible empty positions due to the gravitational force. Empty squares are denoted by a . character, while colored squares can be either red (denoted by P), blue (K) or green (Z). The board is surrounded by a border preventing the colored squares from falling out.

The board can be rotated left or right, or turned upside down. After the rotation or turning, the colored squares will again occupy the lowest free positions. In the example, ``indulás'' is the starting position, ``balra forgatás után'' is the state of the board after a left rotation, and ``függőleges átforgatás után'' is the resulting state after turning the board upside down.

One side of the board contains a hole. In the original position of the board, the hole is found in the K^{\mathrm{th}} column (1\leK\leN) of the bottom row. Colored squares above this hole will always fall out, that is, they are deleted from the board. The example shows a configuration with K=4.

Successive rotations or turning of the board are described by a command string consisting of characters B, J or F: they encode a left rotation, a right rotation, or turning the board upside down, respectively.

Your program i343 should simulate the effect of successive board rotations or turnings as the given command string is executed.

The first command line argument to your program is the name of the data file describing the board and the command string. The first line of the file contains the board size N (1\leN\le50) and the hole position K (1\leK\leN). The following N lines contain the initial positions of the colored and empty squares. The last line of the file gives the command string itself (1\le number of characters \le50).

The second command line argument to your program is the name of the output file. The first 3 lines of this file should contain the remaining number of red (``Piros''), blue (``Kek'') and green (``Zold'') squares after all rotations and turnings have been carried out. The last N lines of the output file should describe the content of each cell of the board after these movements. In the example, ``Bemenet'' is an input, while ``Kimenet'' is the corresponding output.

The source code (i343.pas, i343.cpp, ...) of your program and a brief documentation (i343.txt, i343.pdf, ...) of your solution should be submitted, also specifying the name of the developer environment to use for compiling your source.

(10 pont)

Deadline expired on April 10, 2014.

Sorry, the solution is available only in Hungarian. Google translation

Tesztállományok:,,,,, és

Kimenetek: kimenetek.txt

Minta megoldás:

Csernák Tamás 12. osztályos tanuló (Fazekas Mihály Fővárosi Gyakorló Gimnázium, Budapest) megoldása: i343.pas

Uzonyi Ákos 8. osztályos tanuló (Szent Imre Gimnázium, Budapest) megoldása:


15 students sent a solution.
10 points:Csernák Tamás, Kovács 246 Benedek, Uzonyi 000 Ákos.
9 points:Szécsi Péter.
8 points:6 students.
7 points:2 students.
2 points:3 students.

Problems in Information Technology of KöMaL, March 2014