Advertisement
diyanborisov

LongestAreaInArr

Dec 28th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class LongestAreaInArray
  9. {
  10.     static void Main()
  11.     {
  12.         int n = int.Parse(Console.ReadLine());
  13.         int counter = 0;
  14.         int checkLength = 0;
  15.         string[] words = new string[n];
  16.         List<int> length = new List<int>();
  17.        
  18.         for (int i = 0; i < words.Length; i++)
  19.         {
  20.             words[i] = Console.ReadLine();
  21.         }
  22.  
  23.         string check = words[0];
  24.  
  25.         for (int i = 0; i < words.Length; i++)
  26.         {
  27.             if (check == words[i])
  28.             {
  29.                 check = words[i];
  30.                 counter++;
  31.                 if (i == words.Length - 1)
  32.                 {
  33.                     length.Add(counter);
  34.                    
  35.                 }
  36.             }
  37.             else if (check != words[i])
  38.             {
  39.                 check = words[i];
  40.                 length.Add(counter);
  41.                 counter = 1;
  42.             }
  43.         }
  44.  
  45.         checkLength = length.Max();
  46.  
  47.         if (checkLength == 1)
  48.         {
  49.             Console.WriteLine("\n"+checkLength +"\n"+words[0]);
  50.         }
  51.  
  52.         else if (length.Count == 1)
  53.         {
  54.             Console.WriteLine("\n" + length[0]);
  55.             foreach (string item in words)
  56.             {
  57.                 Console.WriteLine(item);
  58.             }
  59.         }
  60.  
  61.         else
  62.         {
  63.             for (int i = 0; i < words.Length; i++)
  64.             {
  65.  
  66.                 if (check == words[i])
  67.                 {
  68.                     check = words[i];
  69.                     counter++;
  70.                     if (checkLength == counter)
  71.                     {
  72.                         Console.WriteLine("\n" + checkLength);
  73.                         for (int x = 0; x < checkLength; x++)
  74.                         {
  75.                             Console.WriteLine(check);
  76.                         }
  77.                         break;
  78.                     }
  79.  
  80.                 }
  81.  
  82.                 else if (check != words[i])
  83.                 {
  84.                     check = words[i];
  85.                     length.Add(counter);
  86.                     counter = 1;
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement