Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class NeighborElements
- {
- static int colCount;
- static int rolCount;
- static int lonestSequenceCounter = 0;
- static string lonestSequenceStr = " ";
- static string[,] array;
- static bool[,] arrayCheck;
- static void GetLongestSequence(int counter, int rol, int col)
- {
- if (counter > lonestSequenceCounter)
- {
- lonestSequenceCounter = counter;
- lonestSequenceStr = array[rol, col];
- }
- }
- static void MoveRight(int rol, int col, int count)
- {
- if (col >= colCount || rol >= rolCount) return;
- if (array[rol, col] == array[rol, col - 1])
- {
- ++count;
- GetLongestSequence(count, rol, col);
- MoveRight(rol, col + 1, count);
- }
- else
- {
- return;
- }
- }
- static void MoveCorner(int rol, int col, int count)
- {
- if (col >= colCount || rol >= rolCount) return;
- if (array[rol, col] == array[rol - 1, col - 1])
- {
- ++count;
- GetLongestSequence(count, rol, col);
- MoveCorner(rol + 1, col + 1, count);
- }
- else
- {
- return;
- }
- }
- static void MoveDown(int rol, int col, int count)
- {
- if (col >= colCount || rol >= rolCount) return;
- if (array[rol, col] == array[rol - 1, col])
- {
- ++count;
- GetLongestSequence(count, rol, col);
- MoveDown(rol + 1, col, count);
- }
- else
- {
- return;
- }
- }
- static void Main()
- {
- rolCount = int.Parse(Console.ReadLine());
- colCount = int.Parse(Console.ReadLine());
- array = new string[rolCount, colCount];
- // Input data in array
- for (int rol = 0; rol < rolCount; rol++)
- {
- string element = Console.ReadLine();
- string[] dontUse = new string[] { " " };
- string[] elementArray = element.Split(dontUse, StringSplitOptions.RemoveEmptyEntries);
- for (int col = 0; col < elementArray.Length; col++)
- {
- array[rol, col] = elementArray[col];
- }
- }
- // Solution
- for (int rol = 0; rol < rolCount; rol++)
- {
- for (int col = 0; col < colCount; col++)
- {
- MoveRight(rol, col + 1, 1);
- MoveCorner(rol + 1, col + 1, 1);
- MoveDown(rol + 1, col, 1);
- }
- }
- for (int i = 0; i < lonestSequenceCounter; i++)
- {
- Console.Write(lonestSequenceStr + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement