Advertisement
YavorJS

Max_Sequence_of_Equal_Elements

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