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;
- class LongestAreaInArray
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int counter = 0;
- int checkLength = 0;
- string[] words = new string[n];
- List<int> length = new List<int>();
- for (int i = 0; i < words.Length; i++)
- {
- words[i] = Console.ReadLine();
- }
- string check = words[0];
- for (int i = 0; i < words.Length; i++)
- {
- if (check == words[i])
- {
- check = words[i];
- counter++;
- if (i == words.Length - 1)
- {
- length.Add(counter);
- }
- }
- else if (check != words[i])
- {
- check = words[i];
- length.Add(counter);
- counter = 1;
- }
- }
- checkLength = length.Max();
- if (checkLength == 1)
- {
- Console.WriteLine("\n"+checkLength +"\n"+words[0]);
- }
- else if (length.Count == 1)
- {
- Console.WriteLine("\n" + length[0]);
- foreach (string item in words)
- {
- Console.WriteLine(item);
- }
- }
- else
- {
- for (int i = 0; i < words.Length; i++)
- {
- if (check == words[i])
- {
- check = words[i];
- counter++;
- if (checkLength == counter)
- {
- Console.WriteLine("\n" + checkLength);
- for (int x = 0; x < checkLength; x++)
- {
- Console.WriteLine(check);
- }
- break;
- }
- }
- else if (check != words[i])
- {
- check = words[i];
- length.Add(counter);
- counter = 1;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement