Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
113
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.MaxSequenceofEqualElements
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. int counter = 0;
  15. int maxCounter = 0;
  16. int position = 0;
  17.  
  18. for (int i = 0; i < numbers.Length - 1; i++)
  19. {
  20.  
  21. if (numbers[i] == numbers[i + 1])
  22. {
  23.  
  24. counter++;
  25. if (counter>maxCounter)
  26. {
  27. position = i - counter;
  28. maxCounter = counter;
  29. }
  30.  
  31.  
  32.  
  33. }
  34.  
  35. else
  36. {
  37. counter = 0;
  38. }
  39.  
  40.  
  41. }
  42. for (int i = position + 1; i <= position + maxCounter + 1; i++)
  43. {
  44. Console.Write(numbers[i] + " ");
  45. }
  46. Console.WriteLine();
  47.  
  48. }
  49.  
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement