Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CheckStringEqualSequence
- {
- static void Main()
- {
- string[,] matrix = {
- {"ha", "ha", "hi", "hi"},
- {"fo", "ha", "ha", "xx"},
- {"xxx", "fo", "ha", "ha"},
- {"xxx", "1", "fo", "ha"},
- {"xxx", "1", "4", "fo"},
- };
- //string[,] matrix = {
- // {"s", "qq", "s"},
- // {"pp", "pp", "s"},
- // {"pp", "qq", "s"},
- //};
- 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 = 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) - 1 - col < matrix.GetLength(0) - 1) // Check the count ROW or COL is bigger!!!
- {
- myCount2--;
- }
- else
- {
- myCount2 = 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement