Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 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 _01.Max_Sequence_of_Equal_Elements
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> numbers = Console.ReadLine()
  14. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToList();
  17. int start = 0;
  18. int len = 1;
  19. int bestStart = 0;
  20. int bestLen = 1;
  21. bool found = false;
  22. for (int i = 1; i < numbers.Count; i++)
  23. {
  24.  
  25. if (numbers[i] == numbers[i - 1])
  26. {
  27. start = numbers[i];
  28. len++;
  29. found = true;
  30. }
  31. else
  32. {
  33. len = 1;
  34. start = numbers[i];
  35. }
  36. if (len > bestLen)
  37. {
  38. bestStart = start;
  39. bestLen = len;
  40. }
  41. }
  42. if (!found)
  43. {
  44. Console.WriteLine(numbers[0]);
  45. }
  46. else
  47. {
  48. int[] result = new int[bestLen];
  49. for (int i = 0; i < result.Length; i++)
  50. {
  51. result[i] = bestStart;
  52. }
  53. Console.WriteLine(string.Join(" ", result));
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement