Advertisement
Guest User

Max_Sequence_of_Equal_Elements

a guest
Aug 5th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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 _1.Max_Sequence_of_Equal_Elements
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15. int length = 1;
  16. int maxLength = 1;
  17. int position = 0;
  18.  
  19. for (int i = 0; i < nums.Count; i++)
  20. {
  21. if (i > 0 && nums[i] == nums[i - 1])
  22. {
  23. length++;
  24. }
  25. else
  26. {
  27. length = 1;
  28. }
  29. if (maxLength < length)
  30. {
  31. maxLength = length;
  32. position = i+1 -maxLength;
  33. }
  34. }//end of for
  35. //Console.WriteLine(maxLength);
  36. //Console.WriteLine(position);
  37. for (int i = position; i < position + maxLength; i++)
  38. {
  39. Console.Write(nums[i] + " ");
  40. }
  41. Console.WriteLine();
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement