Advertisement
bullit3189

MaxSequenceOfEqualElements-Arrays

Feb 5th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.  
  6. namespace Array
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. var array1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13. int count_max = 0;
  14. int start_max = 0;
  15. int count = 0;
  16. for (int i = 0; i < array1.Length-1; i++)
  17. {
  18. count = 0;
  19. while (array1[i+count]==array1[i+1+count])
  20. {
  21. count++;
  22. if (i + 1 + count > array1.Length - 1)
  23. {
  24. break;
  25. }
  26.  
  27. }
  28. if (count>count_max)
  29. {
  30. count_max = count;
  31. start_max = i;
  32. }
  33.  
  34. }
  35. for (int i = start_max; i <= start_max+ count_max; i++)
  36. {
  37. Console.Write($"{array1[i]} ");
  38. }
  39. Console.WriteLine();
  40.  
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement