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 to from left to right.
The input will contain lines of data. Each line will contain a string of length . The only characters in the string will be the digits through , 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 to .
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 , Blue drops a chip in column .
Red drops a chip in column , Blue drops a chip in column .
Red drops a chip in column , Blue drops a chip in column .
Red drops a chip in column , Blue drops a chip in column .
Red drops a chip in column , Blue drops a chip in column .
Red drops a chip in column .
Red wins!
Comments