11697 - Connect Four   

Description

Connect Four is a classic two-player connection game. How to play it is described as follows:

1. Players chooses colors. In this example, player 1 chooses yellow and player 2 chooses red.

2. They take turns dropping discs from the top of a seven-column, six-row grid. In this example, player 1 drops a yellow disc first, and then player 2 drops a red disc, and so on.

3. The discs fall straight down, occupying the next available space within the column.

4. The player wins if he/she connects four of same colored discs, vertically, horizontally, or diagonally.

Now, we will give you N moves. Please check who win the game or no result.

(Note: There is no draw (win-win) condition in this problem.)

Note:
(1)    In this problem, the winner can only be determined on or after the N-th placement.
(2)    The coordinate of the board’s upper-left intersection is (0,0).

Hint:
Complete the following program.  You only need to write the ‘check result’ part.

 

#include <stdio.h>

char board[6][7];

void show_board(){
        int i, j;
        for( i = 0 ; i < 6 ; i++ ){
                for( j = 0 ; j < 7 ; j++ ){
                        printf( "%c", board[i][j] );
                }
                printf("\n");
        }
}

int main(){

        int i, j;
        int n, col, row;
        int win = 0;
        char color;

        // Initial
        for( i = 0 ; i < 6 ; i++ )
                for( j = 0 ; j < 7 ; j++ )
                        board[i][j] = '-';

        // Get moves
        scanf( "%d", &n );
        while( n-- ){
                getchar();
                scanf( "%d %c", &col, &color );
                // Put the disk
                col--; // Input is 1 ~ 7, but index is 0 ~ 6
		// Fall to the bottom
                for( row = 5 ; row >= 0 && board[row][col] != '-' ; --row );
                board[row][col] = color;
        }

        // check result
	/* Please insert your code here */

        if( win )
                printf("%c win\n", color);
        else
                printf( "No result\n" );
        show_board();

        return 0;

}
 

 

 

Input

The first line is an integer, describing the number of moves, N, 1≤ N ≤ 42. In the following N lines, each
line contains one number and one character: the number K specifies the column id, 
and the character C specifies the color, 1≤K≤7 and C={Y, R}.

Output

The result of the game ( Y win, R win, No result ) and the final map.
Each entry of the map is printed by ‘ %c’, and there is a newline character at the end of the map.

Sample Input  Download

Sample Output  Download

Tags




Discuss