Description
You will be given N functions and their corresponding equations and asked to compute their product. For example, given N = 3, f1(x) = (x+2), f2(x) = (2x+1) and f3(x) = (x+3), then their product f1(x)*f2(x)*f3(x) = (2x3+11x2+17x+6).
Note:
(1) All the coefficients are integers.
(2) The powers of N functions are positive integers and smaller than 100.
(3) 0
The following is an excerpt of incomplete code:
|
#include
int main(){
int m,power[10]; int f[10][100]={0},g[100]={0}; int i,j;
scanf("%d",&m); for(i=0;i scanf("%d",&power[i]); for(j=0;j<=power[i];j++){ scanf("%d",&f[i][j]); } }
/*your code*/
for(i=0;i<=???;i++){ printf("%5d",g[i]); } printf("
");
return 0; } |
Input
There are several lines.
The first line represents N.
The next two lines represent the greatest power of the first equation and the coefficient of the first function.
The next two lines represent the greatest power of the second equation and the coefficient of the second function.
...
The next two lines represent the greatest power of the N-th equation and the coefficient of the N-th function.
Note that the coefficients are descending order and each element is separated by a blank.
Output
The coefficient of the product f1(x)*f2(x)*…*fN(x) with descending order.
Note that you need to use “%5d” to print answer and there is a new line at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Let’s consider the game of Gomoku (五子棋) on a 10x10-intersection board.
l There are two players: black and white. Black plays first.
l The two players (black, white) take turns in placing a stone of their color on an empty intersection.
l The winner is the first player to get an unbroken line of more than five stones horizontally, vertically, or diagonally.
For the following examples, the winners are all the black stone.

In this problem, you will be given a current state of the board game and N individual placements of the two players. You are asked to perform these N placements and finally determine which color wins the game or just show undetermined (UNDET).
Note:
(1) You need to consider the amount of the black and white stones on the current (that is, the given) board state and judge which color plays first in the following N placements.
(2) The winner in this problem can only be determined on or after the N-th placement.
(3) The coordinate of the board’s upper-left intersection is (0,0).
You may use the following piece of code:
|
#include #define B_SIZE 10
char board[B_SIZE][B_SIZE];
void read_board(){ int i, j; for(i = 0; i < B_SIZE; i++){ for(j = 0; j < B_SIZE; j++){ scanf(" %c", &board[i][j]); } } }
void print_board(){ int i, j; for(i = 0; i < B_SIZE; i++){ for(j = 0; j < B_SIZE; j++){ printf(" %c", board[i][j]); } printf("\n"); } }
int main() { int N;
read_board(); scanf("%d", &N);
/* your code here */
//print the result of the game print_board(); return 0; } |
Input
The current state of the board game
N
Position (row, column) of the black or white stone (placement 1)
Position (row, column) of the black or white stone (placement 2)
Position (row, column) of the black or white stone (placement 3)
…
Position (row, column) of the black or white stone (placement N)
Output
There are several lines.
The first line shows “BLACK” if the black stone wins, “WHITE” if the white stone wins, or “UNDET” if the winner cannot be determined.
The following lines show the board state after these N placements.
Each entry of the board is printed using the format “ %c”, and there is a newline character at the end of the board.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains N four-digit integers. For example, if N=9, the input may look like
3412
5232
9128
3456
1324
1928
3344
7631
4343
For each integer, we rearrange its digits from large to small and obtain a new integer. As a result, the nine integers above become
4321
5322
9821
6543
4321
9821
4433
7631
4433
For output, we list the modified integers in a decreasing order line by line. Each integer only needs to be listed once.
9821
7631
6542
5322
4433
4321
You may consider the following algorithm:
0. Create a character array (char str[5];) for storing the input integers and create an array (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 set the value of the corresponding element of the HIT array to 1 (HIT[m]=1;).
3. Check each element of the HIT array; if its value is 1, print the corresponding integer.
Note that the first digit is nonzero.
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.