Advertisement
Guest User

06.LongestAreaInArray

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