Advertisement
whitestarrr

Untitled

Feb 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 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 MostFrequentNumber
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] input =
  14. Console.ReadLine().Split().Select(int.Parse).ToArray();
  15. Dictionary<int, int> occurrences = new Dictionary<int, int>();
  16.  
  17. for (int i = 0; i < input.Length; i++)
  18. {
  19. if (!occurrences.ContainsKey(input[i]))
  20. {
  21. occurrences[input[i]] = 1;
  22. }
  23. else
  24. {
  25. occurrences[input[i]]++;
  26. }
  27. }
  28. var sorted = occurrences.OrderByDescending(x => x.Value).ToArray();
  29. foreach (var o in sorted)
  30. {
  31. Console.WriteLine(o.Key);
  32. break;
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement