Advertisement
GerganaTsirkova

Max Sequence of equal elements

Jan 21st, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 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 MaxSeq
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> num = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14. int maxSeq = 0;
  15. int currSeq = 0;
  16. int counter = 0;
  17. int start = 0;
  18. for (int i = 0; i < num.Count-1; i++)
  19. {
  20. if (num[i] == num[i + 1])
  21. {
  22. currSeq++;
  23. counter++;
  24. if (currSeq > maxSeq)
  25. {
  26. maxSeq = currSeq;
  27. if (counter >= 1)
  28. {
  29. start = num[i];
  30. }
  31. }
  32. }
  33. else
  34. {
  35. counter = 0;
  36. currSeq = 0;
  37. }
  38.  
  39. }
  40. for (int i = 0; i <= maxSeq; i++)
  41. {
  42. Console.Write("{0} ",start);
  43. }
  44.  
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement