| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11145 | Matrix Multiplication |
|
| 11146 | Find the maximum/minimum values |
|
| 11167 | Spiral Text |
|
| 11168 | circulant matrix |
|
| 11169 | Star |
|
| 11170 | The number of occurrences |
|
Description
Given two matrices A and B of size m x n and n x p, calculate C = A x B.
The matrix multiplication is defined as follows:
n
Cij = Σ Aik x Bkj
k=1
Input
m n
A11 A12 ... A1n
...
Am1 Am2 ... Amn
n p
B11 B12 ... B1p
...
Bn1 Bn2 ... Bnp
Each entry is a positive integer no more than 20, and 0 < m, n, p < 10.
Output
C11 C12 ... C1p
...
Cm1 Cm2 ... Cmp
Print each entry with "%d " (a number followed by a whitespace)
Note that there is a newline character at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In this problem, you are asked to implement a program which can find the maximum element M and minimum element mof a two-dimensional array. You need to print the location difference and value difference of M and m. For example, if M is at iM-th row and jM-th column and of value rM, and m is at im-th row and jm-th column and of value rm, then the location difference and value difference of the two elements are (|iM - im| + |jM - jm|) and (|rM - rm|), respectively.
Note that in a given array, no two elements will have the same value.
HINT: You can use C library function: int abs(int x) ,which returns the absolute value of int x.
Before using abs(), you may need to add the following code at first : #include <stdlib.h>
Input
The first line of the input contains two integer numbers R (2<=R<=10) and C (2<=C<=10).
Each of the next R lines contains C integers, specifying the elements of the two-dimensional array. All of the integers in the same line are separated by a space.
Output
The output contains two integers: the location difference and the value difference of the maximum and minimum elements, separated by a space.
Note that you do not need to print ‘\n’ at the end of line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In this problem, you are ask to rearrange a given text in a square and output it in hte "spiral form".
A square is an area with NxN grids. For a given text with length NxN, you put the first character in the upper-left grid. Then, you put the next N-1 characters to the right of the previous one, and you will reach the right border of the square. Any time you can't find an empty place on current direction, you turn "right" and place the next character untile you finish placing all characters and reach the center of the square.
The case below shows the result of a text "0123456789ABCDEF" in a 4x4 square:
0123
BCD4
AFE5
9876
Input
There are 2 lines for the input. The first shows the integer N (1<= N <= 8) denotes the size of the edges of the square. The following line is a text with exactly NxN characters. There might be Alphabets, numbers and spaces in the text.
If you use getchar() to fetch characters in the text, make sure you handle the "new line" ('\n') character in the first line properly.
Output
Print the texts in the square. There should be N lines in the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A circulant matrix is a square matrix in which all column vectors are composed of the same elements and each column vector is rotated one element to the down relative to the preceding column vector.
Given a vector of dimension N, use it to create an N-by-N circulant matrix. An example of circulant matrix:
1 5 4 3 2
2 1 5 4 3
3 2 1 5 4
4 3 2 1 5
5 4 3 2 1
Input
The first line contains a positive integer N indicating the size of the matrix.
The second line contains N numbers indicating the components of the vector. Note that each component of the vector is a one-digit number.
Output
The N-by-N circulant matrix. Print the elements of the matrix using the format "%2d".
Each row is ended with a newline character '\n'.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two integers N and M, and a starting point with coordinates (x, y). You are asked to create an N-by-M matrix as follows.
- Find the matrix element for the starting point, that is, with row index x and column index y, and set this element’s value as 'S'.
- For a matrix element other than the starting point, if its row index is x or its column index is y, then set its value as '+'.
- If a matrix element is on the diagonal line of the starting point, then set its value as '*'.
- For all other matrix elements, set their values as '-'.
Input
Four integers separated by blanks. The first integer (N) represents that the matrix has N rows. The second integer (M) represents that the matrix has M columns. The third integer (X) and the fourth integer (Y) represent the coordinates of the starting point.
( 1 <=N,M<= 15, 0 <= X < N, 0 <= Y < M )
Note that (0, 0) is on the most top-left of the matrix.
Output
The N-by-M matrix. Print the elements of the matrix using the format "%c". Each row is ended with a newline character '\n'.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a string A and n strings B1, B2, B3, …, Bn, count the number of occurrences of string A in each of B1, B2, B3, … , and print the maximum number of occurrences. All of the strings contain only digits.
For example, if A is “50” , n = 3, and the n strings are
“5005”
“055050”
“55000”
then your answer should be 2 because A appears in “5005” one time, in “055050” two times, and in “55000” one time. So the maximum number of occurrences is 2.
Note that if A is “99” and B1 is “9999”, the number of occurrences of A in B1 is counted as 3.
You may assume string B1 is always longer than string A.
Input
The first line of the input is the string A (0<length of A<=4). The second line is n (1<n<10) .
For the next n lines, each line contains a string Bi (length of A < length of Bi <9) and a ‘\n’ at the end of the line.
Output
The maximum number of occurrences of A appears in B1, B2, …, Bn. Note that you DO NOT need to print ‘\n’ at the end of the output.