DWITE Online Computer Programming Contest

Moving at the same time

January 2010
Problem 3

Silly title, but this is exactly what this question addresses. There are too many questions on the CompSci.ca forums asking just that – “I have 2 (or more) characters in my game, how do I move them both at the same time?”. This should be obvious to some, and might sound more complicated than it is to others. Maybe the constraints of this question will provide a clue?

The input file DATA3.txt will contain 5 lines, where each line will describe a game field and characters on it. The size of the field is the size of the line, 1 ≤ N < 20. Periods are empty spaces, whereas integers 0 < C ≤ 3 are characters. The value of the integer represents that character’s speed, in the direction to the right of where they are. Once the character leaves the field, we are no longer concerned with that character. If two characters end up on the same spot, represent them as a sum of their velocities. In the initial input, all of the characters are distinct, and it is guaranteed that the overlapping sum is never greater than 9.

The judge is the observer of the game. Each output line is the judge’s perception of the game (that is, each output line is a frame of this game’s mechanics). If a character’s velocity is 2, then in the time from one frame to the next, that character moves 2 spots to the right.

The output file OUT3.txt will contain 5 sets of output, 5 lines each, being the snapshots of the game field for each game as it progresses – starting with the input state, follewd by 4 frames.

Sample Input (first 2 shown):
Sample Output (first 2 shown):