DWITE Online Computer Programming Contest
February 2006
Problem 4
Connect-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 seven 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 upper case, a hypen (-), 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
Analysis of Sample Input - Second Case
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!
All Submissions
Best Solutions
Point Value: 7
Time Limit: 1.00s
Memory Limit: 16M
Added: Nov 13, 2008
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
It's quiet in here...