Two-dimensional arrays(matrices)-examples
1. Number of bombs in the area
In the Minesweeper game in the fields there are hidden bombs and the task of the player is to find them. The player is presented with a number plate where each number represents the number of bombs that are located around the given field (seeing the surrounding fields in all 8 directions). Your task is to start programming this game by writing a program that specifies these numbers for the bombing schedule.
Input
From the standard input, two numbers m and n represent the dimensions of the table (3≤m, n≤100), followed by a matrix with m type and n column containing zeros and units (where the unit denotes a bomb).
Output
The m × n dimension matrix determines the number of bombs in the vicinity of each array matrix field.
Example
Input
3 4 0 1 0 1 1 0 1 0 0 1 0 0
Output
2 2 3 1 2 4 3 2 2 2 2 1
From the standard input, two numbers m and n represent the dimensions of the table (3≤m, n≤100), followed by a matrix with m type and n column containing zeros and units (where the unit denotes a bomb).
Output
The m × n dimension matrix determines the number of bombs in the vicinity of each array matrix field.
Example
Input
3 4 0 1 0 1 1 0 1 0 0 1 0 0
Output
2 2 3 1 2 4 3 2 2 2 2 1
2. Tournament
During a basketball season, some teams met several times. If the result of each meeting is known, write a program that determines the overall score of all of their encounters after that season.
Input
In the first line of the standard input, the total number of games played is n (1≤n≤100). In the next n-rows, 4 nenegative integers p, q, r, s describing one match are entered, so pp and q (1≤p, q≤10) are regular numbers of basketball teams that played this match with the result r : s (0≤r, s≤150) ie. the team p gave r points, while the q team gave it from the points. After this, the natural number mm (1≤m≤20) is entered, and then m is the pair of natural numbers p and p (1≤p, q≤10).
Output
For each pair of p and q teams, in a separate line, specify how many points the team p gave to the q team and how much the team q gave to the p team, separated by a double.
Example
Input
5
1 2
2 3 90 88
1 2 3 4 5
3 1 88 86
2 3 42 50
2
1 2
3 2
Output
38:79
38: 132
In the first line of the standard input, the total number of games played is n (1≤n≤100). In the next n-rows, 4 nenegative integers p, q, r, s describing one match are entered, so pp and q (1≤p, q≤10) are regular numbers of basketball teams that played this match with the result r : s (0≤r, s≤150) ie. the team p gave r points, while the q team gave it from the points. After this, the natural number mm (1≤m≤20) is entered, and then m is the pair of natural numbers p and p (1≤p, q≤10).
Output
For each pair of p and q teams, in a separate line, specify how many points the team p gave to the q team and how much the team q gave to the p team, separated by a double.
Example
Input
5
1 2
2 3 90 88
1 2 3 4 5
3 1 88 86
2 3 42 50
2
1 2
3 2
Output
38:79
38: 132
3. Matrix mapping example
The children were preparing an event in the school yard. Each was wearing a costume of different colors and they looked like a square matrix. During the point of the children, they moved and in very correct ways. First, they matched the matrix around the main diagonal. Then they rolled the matrix 90 degrees to the right (clockwise). After that, they were mapped horizontally and in the end they were mapped around the secondary diagonal. Write a program that prints the color scheme of children's bones after each step of their choreography.
Input
From the standard input, the number n (3≤n≤10) is loaded, and then the square matrix of dimension n containing numbers between 0 and 10 (each number denotes one color of the bones).
Output
The standard output outputs 5 matrices. The starting, loaded, and then the matrix obtained after each transformation.
Example
Input
3
1 2 3
4 5 6
7 8 9
Output
1 2 3
4 5 6
7 8 9
1 4 7
2 5 8
3 6 9
3 2 1
6 5 4
9 8 7
9 8 7
6 5 4
3 2 1
1 4 7
2 5 8
3 6 9
From the standard input, the number n (3≤n≤10) is loaded, and then the square matrix of dimension n containing numbers between 0 and 10 (each number denotes one color of the bones).
Output
The standard output outputs 5 matrices. The starting, loaded, and then the matrix obtained after each transformation.
Example
Input
3
1 2 3
4 5 6
7 8 9
Output
1 2 3
4 5 6
7 8 9
1 4 7
2 5 8
3 6 9
3 2 1
6 5 4
9 8 7
9 8 7
6 5 4
3 2 1
1 4 7
2 5 8
3 6 9
Related articles
Useful site Geek For Geeks: https://www.geeksforgeeks.org/multidimensional-arrays-c-cpp/
Introduce about two-dimensional array: Two dimensional array-matrix