DWITE '06 R5 #4 - Connect-4

View as PDF

Submit solution

Points: 7
Time limit: 0.6s
Memory limit: 16M

Problem type
DWITE Online Computer Programming Contest, February 2006, Problem 4

The rules for Connect-4 are simple. The game is played on an upright seven column board. Each column has six spots. Two players play by alternately dropping a red chip or a blue chip down one of the columns. The chip drops to the lowest unoccupied spot in that column. The first player to get four chips in a row, of their colour, either vertical, horizontal, or diagonal, wins. The game ends in a stalemate if it fills before someone wins.

An empty Connect-4 board looks as follows. Columns of the board will be numbered 1 to 7 from left to right.

The input will contain 5 lines of data. Each line will contain a string of length 42. The only characters in the string will be the digits 1 through 7, indicating the column that the chip is dropped in. The first digit in the string, and every other digit after that will represent the column that a red chip is dropped in. The second digit in the string, and every other digit after that will represent the column that a blue chip is dropped in. There will be exactly six of each of the digits 1 to 7.

The output will contain five lines of data. Each line will contain the colour of the winner in uppercase, a hyphen (-), and the total number of chips dropped when the winner was declared.

Note: There will be a winner in each case.

Sample Input

212343342254453665554756111121237776767643
433242522131111122333444455555666666777777
333242236724226611111133344455555566677777

Sample Output

RED-23
RED-11
BLUE-18

Explanation for Sample 2

Red drops a chip in column 4, Blue drops a chip in column 3.
Red drops a chip in column 3, Blue drops a chip in column 2.
Red drops a chip in column 4, Blue drops a chip in column 2.
Red drops a chip in column 5, Blue drops a chip in column 2.
Red drops a chip in column 2, Blue drops a chip in column 1.
Red drops a chip in column 3.
Red wins!


Comments

There are no comments at the moment.