Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CheckStringEqualSequence
- {
- static void Main()
- {
- string[,] matrix = {
- {"01", "02", "03", "11", "06", "06", "07", "15"},
- {"09", "10", "11", "12", "06", "14", "15", "16"},
- {"17", "11", "19", "21", "22", "01", "16", "06"},
- {"26", "17", "28", "29", "15", "16", "32", "33"},
- {"34", "35", "36", "15", "38", "39", "40", "41"},
- };
- int countVertical = 0;
- int countHorizontal = 0;
- int countDiagonalLeftUp = 0;
- int countDiagoanlRightUp = 0;
- string strVertical = null;
- string strHorizontal = null;
- string strDiagonalLeftUp = null;
- string strDiagonalRightUp = null;
- // Horizontal - row
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- int currentCount = 0;
- for (int col = 0; col < matrix.GetLength(1) - 1; col++)
- {
- if (matrix[row, col] == matrix[row, col + 1])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countHorizontal < currentCount)
- {
- countHorizontal = currentCount;
- strHorizontal = matrix[row, col];
- }
- }
- }
- // Vertical - col
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- int currentCount = 0;
- for (int row = 0; row < matrix.GetLength(0) - 1; row++)
- {
- if (matrix[row, col] == matrix[row + 1, col])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countVertical < currentCount)
- {
- countVertical = currentCount;
- strVertical = matrix[row, col];
- }
- }
- }
- // LeftUp - Diagonal --- (last row - 1 ) to (first row)
- int myCount1 = 1;
- for (int row = matrix.GetLength(0) - 2; row >= 0; row--)
- {
- int currentCount = 0;
- for (int col = 0; col < myCount1; col++)
- {
- if (matrix[row + col, col] == matrix[row + col + 1, col + 1])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countDiagonalLeftUp <= currentCount)
- {
- countDiagonalLeftUp = currentCount;
- strDiagonalLeftUp = matrix[row + col, col];
- }
- }
- if (matrix.GetLength(0) - 1 - row < matrix.GetLength(1) - 1) // Check the count ROW or COL is bigger!!!
- {
- myCount1++;
- }
- else
- {
- myCount1 = matrix.GetLength(1) - 1;
- }
- }
- // LeftUp - Diagonal --- (first row ) to (last col)
- int myCount2 = 0;
- if (matrix.GetLength(0) >= matrix.GetLength(1))
- {
- myCount2 = matrix.GetLength(1) - 2;
- }
- else
- {
- myCount2 = matrix.GetLength(0) - 1;
- }
- for (int col = 1; col < matrix.GetLength(1) - 1; col++)
- {
- int currentCount = 0;
- for (int row = 0; row < myCount2; row++)
- {
- if (matrix[row, col + row] == matrix[row + 1, col + row + 1])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countDiagonalLeftUp <= currentCount)
- {
- countDiagonalLeftUp = currentCount;
- strDiagonalLeftUp = matrix[row, col + row];
- }
- }
- if (matrix.GetLength(1) - 2 - col < matrix.GetLength(0) - 1) // Check the count ROW or COL is bigger!!!
- {
- myCount2--;
- }
- else
- {
- myCount2 = matrix.GetLength(0) - 1;
- }
- }
- // RightUp - Diagonal --- (last row - 1 ) to (first row)
- int myCount3 = matrix.GetLength(1) - 2;
- for (int row = matrix.GetLength(0) - 2; row >= 0; row--)
- {
- int currentCount = 0;
- for (int col = matrix.GetLength(1) - 1; col > myCount3; col--)
- {
- int ss = (matrix.GetLength(1) - 1 - col);
- if (matrix[row + ss, col] == matrix[row + ss + 1, col - 1])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countDiagoanlRightUp < currentCount)
- {
- countDiagoanlRightUp = currentCount;
- strDiagonalRightUp = matrix[row + ss, col];
- }
- }
- if (matrix.GetLength(0) - 1 - row < matrix.GetLength(1) - 1) // Check the count ROW or COL is bigger!!!
- {
- myCount3--;
- }
- else
- {
- myCount3 = matrix.GetLength(1) - 1;
- }
- }
- // RightUp - Diagonal --- (first row ) to (last col)
- int myCount4 = 0;
- if (matrix.GetLength(0) >= matrix.GetLength(1))
- {
- myCount4 = matrix.GetLength(1) - 2;
- }
- else
- {
- myCount4 = matrix.GetLength(0) - 1;
- }
- for (int col = matrix.GetLength(1) - 1; col > 0; col--)
- {
- int currentCount = 0;
- for (int row = 0; row < myCount4; row++)
- {
- if (matrix[row, col - row - 1] == matrix[row + 1, col - row - 2])
- {
- currentCount++;
- }
- else
- {
- currentCount = 0;
- }
- if (countDiagoanlRightUp < currentCount)
- {
- countDiagoanlRightUp = currentCount;
- strDiagonalRightUp = matrix[row, col - row - 1];
- }
- }
- if (col <= matrix.GetLength(0)) // Check the count ROW or COL is bigger!!!
- {
- myCount4--;
- }
- else
- {
- myCount4 = matrix.GetLength(0) - 1;
- }
- }
- // Print the result
- Console.Write("The Horizontal is: ");
- for (int i = 0; i <= countHorizontal; i++)
- {
- Console.Write(strHorizontal + " ");
- }
- Console.WriteLine();
- Console.Write("The Vertical is: ");
- for (int i = 0; i <= countVertical; i++)
- {
- Console.Write(strVertical + " ");
- }
- Console.WriteLine();
- Console.Write("The LeftUp Diagonal is: ");
- for (int i = 0; i <= countDiagonalLeftUp; i++)
- {
- Console.Write(strDiagonalLeftUp + " ");
- }
- Console.WriteLine();
- Console.Write("The RightUp Diagonal is: ");
- for (int i = 0; i <= countDiagoanlRightUp; i++)
- {
- Console.Write(strDiagonalRightUp + " ");
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement