Advertisement
TzvetanIG

Longest Area in Array

Mar 30th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. class LongestAreaInArray
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         string[] strings = new string[n];
  9.  
  10.         for (int i = 0; i < strings.Length; i++)
  11.         {
  12.             strings[i] = Console.ReadLine();
  13.         }
  14.  
  15.         int maxLenght = int.MinValue;
  16.         string areaStr = strings[0];
  17.         int count = 0;
  18.         string curentStr = strings[0];
  19.  
  20.         for (int i = 0; i < strings.Length; i++)
  21.         {
  22.             if (curentStr == strings[i])
  23.             {
  24.                 count++;
  25.             }
  26.             else
  27.             {
  28.                 curentStr = strings[i];
  29.                 count = 1;
  30.             }
  31.  
  32.             if (count > maxLenght)
  33.             {
  34.                 maxLenght = count;
  35.                 areaStr = curentStr;
  36.             }
  37.  
  38.        }
  39.  
  40.        PrintResult(maxLenght, areaStr);
  41.  
  42.     }
  43.  
  44.     static void PrintResult(int maxLenght, string areaStr)
  45.     {
  46.         Console.WriteLine(maxLenght);
  47.         for (int i = 0; i < maxLenght; i++)
  48.         {
  49.             Console.WriteLine(areaStr);
  50.         }
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement