Hi there is a two-dimensional array
string[,] Array = new string[9,9]; It is necessary to find more than 5 identical symbols on the diagonal.
Hi there is a two-dimensional array
string[,] Array = new string[9,9]; It is necessary to find more than 5 identical symbols on the diagonal.
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
For this action two steps are enough:
So, step number 1:
Let's look at three arrays:
var matrix2D = [ 1, 2, 3, 4 ]; var matrix3D = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; var matrix4D = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ]; If you look closely, you can see the logic by which the numbers are located on the diagonal: the row number and the column number are the same. Knowing it is not difficult to make two cycles with counters i and j , and if they match, enter the number in an additional array (let's call it arr2 ).
Step # 2:
At this step, you need to count the number of occurrences of numbers and filter by condition. How to do it? Ways to a lot:
One way is to use LINQ by selecting from the array exactly those numbers that are greater than 5. For sampling, you can use GroupBy - to group values, Where - to filter by condition (> 5)) and Select for the sample itself. All methods can be found in the Documentation.
Another way: to get a dictionary (Dictionary), where the key is a number, and the value is the number of repetitions of this number. Then make a loop, and at iteration check:
As a result, getting the desired result.
Choose a way and think ...
Happy End.
Source: https://ru.stackoverflow.com/questions/666157/
All Articles