Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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. // Write a program to find the longest area of equal elements in array of strings.
  8. // You first should read an integer n and n strings (each at a separate line),
  9. // then find and print the longest sequence of equal elements (first its length, then its elements).
  10. // If multiple sequences have the same maximal length, print the leftmost of them.
  11.  
  12. class Pr06LongestAreaInArray
  13. {
  14.     static void Main(string[] args)
  15.     {
  16.         int amountOfStrings = int.Parse(Console.ReadLine());
  17.         string lastString = "";
  18.         string biggestString = "";
  19.         int biggestCounter = 0;
  20.         int counter = 1;
  21.         for (int i = 0; i < amountOfStrings; i++)
  22.         {
  23.             string currentString = Console.ReadLine();
  24.             if(currentString.Equals(lastString))
  25.             {
  26.                 counter++;
  27.             }
  28.             else
  29.             {
  30.                 counter = 1;
  31.             }
  32.             if(biggestCounter < counter)
  33.             {
  34.                 biggestCounter = counter;
  35.                 biggestString = currentString;
  36.             }
  37.             lastString = currentString;
  38.         }
  39.         Console.WriteLine(biggestCounter);
  40.         for (int i = 0; i < biggestCounter; i++)
  41.         {
  42.             Console.WriteLine(biggestString);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement