Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 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 arrays
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int count = 1;
  15. int currentIndex = 0;
  16. int bestIndex = 0;
  17. int bestcount = 0;
  18. for (int i = 1; i < arr.Length; i++)
  19. {
  20. if (arr[i] == arr[currentIndex])
  21. {
  22. count++;
  23. if (count>bestcount)
  24. {
  25. bestcount = count;
  26. bestIndex = currentIndex;
  27. }
  28.  
  29. }
  30. else
  31. {
  32. count--;
  33. }
  34. if (count == 0)
  35. {
  36. currentIndex = i;
  37. count = 1;
  38. }
  39. }
  40.  
  41. int mostFreq = arr[bestIndex];
  42. Console.WriteLine(mostFreq);
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement