11 machine test of Beihang
"Problem description"
Enter the two matrices A and B, and then enter the replacement position (upper left), where the program replaces the matrix A (same size as B) with B, and outputs the substituted matrix.
"Input Form"
From the console, enter the number of rows and columns of matrix A (both rows and columns are greater than or equal to 1, less than or equal to 20), and then enter the number of rows (in a space-delimited integer) of the matrix A on the new row. And then enter the Matrix B in the same way. Finally, enter a replacement position (two integers separated by a space, with the number of rows and columns counting from 1, so that two integers are greater than or equal to 1). If the replacement position exceeds the number of rows or columns of matrix A, the matrix A is output as is.
"Output Form"
In the standard output, the branch outputs the replacement matrix, separated by a space between the digits in each row.
"Input Sample 1"
5 6
10 2 34-1 800 90
2 76 56-200 23 1
35 0 0 98 8 3000
2000 100-1 1 2 0
8 7 85 963 496 8
2 3
9 9 9
9 9 9
3 3
"Output Sample 1"
10 2 34-1 800 90
2 76 56-200 23 1
35 0 9 9 9 3000
2000 100 9 9 9 0
8 7 85 963 496 8
"Sample 1 description"
The input matrix A is 5 rows, 6 columns, and Matrix B is 2 rows, 3 columns, and the replacement position is the 3rd column of row 3rd, which replaces the sub matrix with the number 2 columns of column A and the 3rd row in a, with B.
"Input Sample 2"
3 4
10 2 34-1
2 76 56-200
35 0 0 98
2 3
9 9 9
9 9 9
2 3
"Output Sample 2"
10 2 34-1
2 76 9 9
35 0 9 9
"Sample 2 description"
The input matrix A is 3 rows, 4 columns, and Matrix B is 2 rows, 3 columns, and the replacement position is the 3rd column of row 2nd, which replaces the sub matrix with the number 2 columns of column A and the 2nd row in a, with B. But the child matrix is beyond the range of a, so only partial substitutions are implemented.
#include <stdio.h>
int main () {
int i,j;
int r,c;
int SR,SC;
int x,y;
int init[20][20]={0};
int s[20][20]={0};
Freopen ("4.txt", "R", stdin);/To simplify input, redirect input, directly read the contents of Notepad
scanf ("%d%d", &r,&c);
for (i=0;i<r;i++) {
for (j=0;j<c;j++)
scanf ("%d", &init[i][j]);
scanf ("%d%d", &SR,&SC);
for (i=0;i<sr;i++) {
for (j=0;j<sc;j++)
scanf ("%d", &s[i][j]);
scanf ("%d%d", &x,&y);
for (i=0;i<sr;i++) {//Replace array content with for
(j=0;j<sc;j++)
if (i+x-1<r&&j+y-1<c)
init[i+ X-1][J+Y-1]=S[I][J];
}
for (i=0;i<r;i++) {
for (j=0;j<c;j++)
printf ("%d", init[i][j]);
printf ("\ n");
}
return 0;
}