Advertisement
soxa

lonestSequence

Dec 25th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2.  
  3. class NeighborElements
  4. {
  5.     static int colCount;
  6.     static int rolCount;
  7.     static int lonestSequenceCounter = 0;
  8.     static string lonestSequenceStr = " ";
  9.     static string[,] array;
  10.     static bool[,] arrayCheck;
  11.  
  12.     static void GetLongestSequence(int counter, int rol, int col)
  13.     {
  14.         if (counter > lonestSequenceCounter)
  15.         {
  16.             lonestSequenceCounter = counter;
  17.             lonestSequenceStr = array[rol, col];
  18.         }
  19.     }
  20.  
  21.     static void MoveRight(int rol, int col, int count)
  22.     {
  23.         if (col >= colCount || rol >= rolCount) return;
  24.         if (array[rol, col] == array[rol, col - 1])
  25.         {
  26.             ++count;
  27.             GetLongestSequence(count, rol, col);
  28.             MoveRight(rol, col + 1, count);
  29.         }
  30.         else
  31.         {
  32.             return;
  33.         }
  34.     }
  35.  
  36.     static void MoveCorner(int rol, int col, int count)
  37.     {
  38.         if (col >= colCount || rol >= rolCount) return;
  39.         if (array[rol, col] == array[rol - 1, col - 1])
  40.         {
  41.             ++count;
  42.             GetLongestSequence(count, rol, col);
  43.             MoveCorner(rol + 1, col + 1, count);
  44.         }
  45.         else
  46.         {
  47.             return;
  48.         }
  49.     }
  50.  
  51.     static void MoveDown(int rol, int col, int count)
  52.     {
  53.         if (col >= colCount || rol >= rolCount) return;
  54.  
  55.         if (array[rol, col] == array[rol - 1, col])
  56.         {
  57.             ++count;
  58.             GetLongestSequence(count, rol, col);
  59.             MoveDown(rol + 1, col, count);
  60.         }
  61.         else
  62.         {
  63.             return;
  64.         }
  65.     }
  66.  
  67.     static void Main()
  68.     {
  69.         rolCount = int.Parse(Console.ReadLine());
  70.         colCount = int.Parse(Console.ReadLine());
  71.         array = new string[rolCount, colCount];
  72.  
  73.         // Input data in array
  74.         for (int rol = 0; rol < rolCount; rol++)
  75.         {
  76.             string element = Console.ReadLine();
  77.             string[] dontUse = new string[] { " " };
  78.             string[] elementArray = element.Split(dontUse, StringSplitOptions.RemoveEmptyEntries);
  79.  
  80.             for (int col = 0; col < elementArray.Length; col++)
  81.             {
  82.                 array[rol, col] = elementArray[col];
  83.             }
  84.         }
  85.  
  86.         // Solution
  87.         for (int rol = 0; rol < rolCount; rol++)
  88.         {
  89.             for (int col = 0; col < colCount; col++)
  90.             {
  91.                 MoveRight(rol, col + 1, 1);
  92.                 MoveCorner(rol + 1, col + 1, 1);
  93.                 MoveDown(rol + 1, col, 1);
  94.             }
  95.         }
  96.  
  97.         for (int i = 0; i < lonestSequenceCounter; i++)
  98.         {
  99.             Console.Write(lonestSequenceStr + " ");
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement