Advertisement
whitestarrr

Untitled

Oct 22nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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 MaxSequenceOfEqualElements
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int count = 1;
  15. int max = 0;
  16. int start = 0;
  17. int bestLenght = 0;
  18. for (int i = 0; i < input.Length - 1; i++)
  19. {
  20. if (input[i]+1 == input[i + 1])
  21. {
  22. count++;
  23. if (count > max)
  24. {
  25. max = count;
  26. start = input[i];
  27. }
  28. }
  29. else
  30. {
  31. count = 1;
  32. }
  33. if (max == 1)
  34. {
  35. start = input[i];
  36. }
  37. bestLenght = start;
  38. }
  39. var result = input.Skip(start-2).Take(max);
  40. Console.WriteLine(string.Join(" ", result));
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement