Advertisement
Guest User

Untitled

a guest
Apr 6th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1.  using System;
  2.  using System.Text;
  3.  class LongestAreaInArray
  4.     {
  5.         static void Main()
  6.         {
  7.             int n = int.Parse(Console.ReadLine());
  8.  
  9.             string[] strings = new string[n];
  10.  
  11.             int count = 1;
  12.             int maxCount = 1;
  13.             string theWord;
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 strings[i] = Console.ReadLine().Trim();
  17.             }
  18.             theWord = strings[0];
  19.  
  20.             for (int i = 0; i < strings.Length - 1; i++)
  21.             {
  22.                 if (strings[i] == strings[i + 1])
  23.                 {
  24.                     count++;
  25.                     if (count > maxCount)
  26.                     {
  27.                         maxCount = count;
  28.                         theWord = strings[i];
  29.                     }
  30.                 }
  31.                 else
  32.                 {
  33.                     count = 1;
  34.                 }
  35.             }
  36.             var sb = new StringBuilder();
  37.             sb.AppendLine(maxCount.ToString());
  38.             for (int i = 0; i < maxCount; i++)
  39.             {
  40.                 sb.AppendLine(theWord);
  41.             }
  42.             Console.WriteLine();
  43.             Console.Write(sb);
  44.         }
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement