remote87

Longest area in array

Sep 17th, 2015
201
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03.LongestAreaInArray
  8. {
  9.     class LongestAreaInArray
  10.     {
  11.         static void Main()
  12.         {
  13.             int amountOfStrings = int.Parse(Console.ReadLine());
  14.             string lastString = "";
  15.             string biggestString = "";
  16.             int biggestCounter = 0;
  17.             int counter = 1;
  18.             for (int i = 0; i < amountOfStrings; i++)
  19.             {
  20.                 string currentString = Console.ReadLine();
  21.                 if (currentString.Equals(lastString))
  22.                 {
  23.                     counter++;
  24.                 }
  25.                 else
  26.                 {
  27.                     counter = 1;
  28.                 }
  29.                 if (biggestCounter < counter)
  30.                 {
  31.                     biggestCounter = counter;
  32.                     biggestString = currentString;
  33.                 }
  34.                 lastString = currentString;
  35.             }
  36.             Console.WriteLine(biggestCounter);
  37.             for (int i = 0; i < biggestCounter; i++)
  38.             {
  39.                 Console.WriteLine(biggestString);
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment