Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class LongestArea
- {
- static void Main()
- {
- Console.Write("Enter how much words you will input: ");
- int n = int.Parse(Console.ReadLine());
- string[] arr = new string[n];
- for (int i = 0; i < arr.Length; i++)
- {
- Console.Write("Enter word {0}: ", i + 1);
- arr[i] = Console.ReadLine();
- }
- int longest = 0;
- int currElem = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- int counter = 0;
- for (int j = i; j < arr.Length; j++)
- {
- if (arr[i] == arr[j])
- counter++;
- }
- if (counter > longest)
- {
- longest = counter;
- currElem = i;
- }
- }
- Console.WriteLine("The longest sequence of words is: "+longest);
- for (int i = 0; i < arr.Length; i++)
- {
- if(arr[i]==arr[currElem])
- Console.WriteLine(arr[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment