alestori

Untitled

Oct 5th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class MostFrequentNumber
  6. {
  7. static void Main()
  8. {
  9. var seqNums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  10. int[] counts = new int[seqNums.Max() + 1];
  11.  
  12. foreach (var num in seqNums)
  13. {
  14. counts[num]++;
  15. }
  16.  
  17.  
  18. var maxInCounts = new List<int>();
  19. int maxNuminCounters = counts.Max();
  20.  
  21. for (int i = 0; i < counts.Length; i++)
  22. {
  23. if (counts[i] == counts.Max())
  24. {
  25. maxInCounts.Add(i);
  26. }
  27. }
  28. for (int i = 0; i < seqNums.Length; i++)
  29. {
  30. if (maxInCounts.Contains(seqNums[i]))
  31. {
  32. Console.WriteLine(seqNums[i]);
  33. break;
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment