Advertisement
Guest User

Untitled

a guest
Mar 14th, 2018
1,404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11. int start = 0;
  12. int length = 1;
  13. int beststart = 0;
  14. int bestLength = 1;
  15.  
  16. for (int i = 1; i <= input.Length - 1; i++)
  17. {
  18. if (input[i] == input[i - 1])
  19. {
  20. length++;
  21. }
  22. else
  23. {
  24. if (length > bestLength)
  25. {
  26. bestLength = length;
  27. length = 1;
  28. beststart = start;
  29. start = i;
  30. }
  31. else if (length == bestLength)
  32. {
  33. length = 1;
  34. start = i;
  35. }
  36. else
  37. {
  38. length = 1;
  39. start = i;
  40. }
  41. }
  42. }
  43.  
  44. if (length > bestLength)
  45. {
  46. bestLength = length;
  47.  
  48. beststart = start;
  49. }
  50.  
  51. if (bestLength == 1)
  52. {
  53. Console.WriteLine(input[0]);
  54. return;
  55. }
  56.  
  57. var result = string.Concat(input);
  58. var sub = result.Substring(beststart, bestLength).Trim();
  59. //var final = sub.ToCharArray();
  60. var final = input.Skip(beststart).Take(bestLength).ToArray();
  61. Console.WriteLine(string.Join(" ", final));
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement