| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10348 | Four in a line |
|
| 10349 | license |
|
| 10350 | multiply transpose matrix |
|
Description
Connect Four( also known as Four in a line) 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.
.gif)
(From wikpedia: Connect Four)
Now, we will give you N moves. Please check who win the game or no result.
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).
.png)
Hint:
Complete the following program. You only need to write the ‘check result’ part.
#includechar 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
Description
Problem Description
There are N license. Each license has four-digit integer. For example, if N=7, the input may look like
7
5566
1324
3578
4123
5656
4312
9841
We want to get the licenses that use the same digits and the digits should be sorted from small to large. For example, 1324, 4123, and 4312 are the combination of the same digits (1, 2, 3, and 4). We want to get 1234. Similarly, 5566 and 5656 are the combination of the same digits (5, 5, 6, and 6). We want to get 5566.
For output, we list the modified licenses in an increasing order line by line, so the output will look
1234
5566
You may consider the following algorithm:
0. Create a character array (char *str[5];) for storing the input integers and create an array which is initialed to zero (int HIT[10000];) to record the occurrences of input integers.
1. Read the number of input integers and store it in variable N (scanf("%d", &N);).
2. For each of the next N integers, do
2.1 Read the four-digit integer and store it as a four-character string in str.
2.2 Use the bubble sort algorithm to rearrange the four characters.
2.3 Convert the rearranged string to an integer m and increase the value of the corresponding element of the HIT array by 1 (HIT[m]++;).
3. Check each element of the HIT array; if its value is larger than 2, print the corresponding integer.
The bubble sort algorithm:
/* Using bubble sort to rearrange an array A[n] */
for (i = 0; i < n; i++) {
for (j = 1; j < n; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
Input
The first line contains a number N (1<=N<=100).
The next N lines provide the N four-digit integers.
Output
Each line shows a modified unique integer as explained in the problem description.
Remember to print a newline at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a matrix A, output the matrix multiply by its transpose matrix.


.png)
.png)
.png)
Input
Both n and m will be less than 10 and bigger than 1.
Output
Output the result of A multiplying with the transpose matrix of A.
Use "%5d" for each value.