Advertisement
Guest User

MostFrequentNumber

a guest
Jan 31st, 2017
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace MostFrequentNumber
  5. {
  6. class MostFrequentNumber
  7. {
  8. public static void Main(string[] args)
  9. {
  10. int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11. int counter = 0;
  12. int number = 0;
  13. int maxCounter = 0;
  14.  
  15. for (int i = 0; i < numbers.Length; i++)
  16. {
  17. for (int j = i+1; j < numbers.Length; j++)
  18. {
  19. if (numbers[i] == numbers[j])
  20. {
  21. counter++;
  22.  
  23. if (counter > maxCounter )
  24. {
  25. number = numbers[i];
  26. maxCounter = counter;
  27. }
  28. else
  29. {
  30. counter = 0;
  31.  
  32. }
  33.  
  34. }
  35. }
  36. }
  37. Console.WriteLine(number);
  38.  
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement