Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 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[] numbers = Console.ReadLine()
  14. .Split(' ')
  15. .Select(int.Parse)
  16. .ToArray();
  17.  
  18. int[] values = new int[numbers.Length];
  19. int[] amount = new int[numbers.Length];
  20. int valueIndexToPush = 0;
  21. for (int i = 0; i < numbers.Length; i++)
  22. {
  23. int index = Array.IndexOf(values, numbers[i]);
  24. if (index > -1)
  25. {
  26. amount[index]++;
  27. }
  28. else
  29. {
  30. values[valueIndexToPush] = numbers[i];
  31. amount[valueIndexToPush] = 1;
  32. valueIndexToPush++;
  33. }
  34. }
  35.  
  36. int max = amount.Max();
  37. int indexOfMax = Array.IndexOf(amount, max);
  38.  
  39. Console.WriteLine(values[indexOfMax]);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement