Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- // Write a program to find the longest area of equal elements in array of strings.
- // You first should read an integer n and n strings (each at a separate line),
- // then find and print the longest sequence of equal elements (first its length, then its elements).
- // If multiple sequences have the same maximal length, print the leftmost of them.
- class Pr06LongestAreaInArray
- {
- static void Main(string[] args)
- {
- int amountOfStrings = int.Parse(Console.ReadLine());
- string lastString = "";
- string biggestString = "";
- int biggestCounter = 0;
- int counter = 1;
- for (int i = 0; i < amountOfStrings; i++)
- {
- string currentString = Console.ReadLine();
- if(currentString.Equals(lastString))
- {
- counter++;
- }
- else
- {
- counter = 1;
- }
- if(biggestCounter < counter)
- {
- biggestCounter = counter;
- biggestString = currentString;
- }
- lastString = currentString;
- }
- Console.WriteLine(biggestCounter);
- for (int i = 0; i < biggestCounter; i++)
- {
- Console.WriteLine(biggestString);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement