Advertisement
Guest User

Untitled

a guest
May 22nd, 2020
119
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.  
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. int[] numbers = Console.ReadLine()
  13. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  14. .Select(int.Parse)
  15. .ToArray();
  16.  
  17. int occurence = 1;
  18. int biggestOccurence = 0;
  19. int mostCommonNumber = 0;
  20.  
  21. for (int i = 0; i < numbers.Length; i++)
  22. {
  23. int previous = numbers[i];
  24. for (int j = i + 1; j < numbers.Length - 1; j++)
  25. {
  26. int current = numbers[j];
  27. if (previous == current)
  28. {
  29. occurence++;
  30. if (occurence > biggestOccurence)
  31. {
  32. biggestOccurence = occurence;
  33. mostCommonNumber = current;
  34. }
  35. }
  36. else
  37. {
  38. occurence = 1;
  39. }
  40. }
  41.  
  42. }
  43. Console.WriteLine(mostCommonNumber);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement