Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleTesting
- {
- internal class ConsoleTesting
- {
- private static void Main()
- {
- Console.Write("Enter the length of the array: ");
- int n = int.Parse(Console.ReadLine());
- var arrayInt = new int[n];
- var seqList = new List<string>();
- var seqCounts = new List<int>();
- for (int i = 0; i < arrayInt.Length; i++)
- {
- Console.Write("Index \"{0}\": ", i);
- arrayInt[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < arrayInt.Length;)
- {
- int temp = arrayInt[i];
- var tempSeq = new List<string>();
- tempSeq.Add(Convert.ToString(temp));
- while (i + 1 < arrayInt.Length && arrayInt[i + 1] == temp)
- {
- tempSeq.Add(Convert.ToString(arrayInt[i + 1]));
- i++;
- }
- if (tempSeq.Count > 1)
- {
- string tempovSeq = string.Join(",", tempSeq);
- seqList.Add(tempovSeq);
- seqCounts.Add(tempSeq.Count);
- i++;
- }
- else
- {
- i++;
- }
- }
- if (seqList.Count == 0)
- {
- Console.WriteLine();
- Console.WriteLine("No consecutive sequences with at least two members found! Exiting...");
- Console.WriteLine();
- return;
- }
- else if (seqList.Count == 1)
- {
- Console.WriteLine();
- Console.WriteLine("Only one sequence with at least two members found: " + seqList[0]);
- Console.WriteLine();
- return;
- }
- Console.WriteLine();
- Console.WriteLine("Consecutive sequences with at least two members: ");
- foreach (string seq in seqList)
- {
- Console.WriteLine(seq);
- }
- Console.WriteLine();
- var allAreSame = seqCounts.Distinct().Count() == 1;
- if (allAreSame==true)
- {
- Console.WriteLine("All sequences have equal length");
- Console.WriteLine();
- return;
- }
- else
- {
- int maxIndex = seqCounts.IndexOf(seqCounts.Max());
- Console.WriteLine("The longest sequence is: \"{0}\"", seqList[maxIndex]);
- Console.WriteLine();
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment