Advertisement
aslv

Longest Area in Array

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