VPanev

Untitled

Nov 18th, 2021
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ConsoleApp1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. int counter = 1;
  13. int maxCounter = 0;
  14. int[] numbersArray = new int[n];
  15. int num = 0;
  16. for (int i = 0; i < n; i++)
  17. {
  18. numbersArray[i] = int.Parse(Console.ReadLine());
  19. }
  20. Array.Sort(numbersArray);
  21. if (n == 1)
  22. {
  23. num = numbersArray[0];
  24. }
  25. for (int i = 0; i < n - 1; i++)
  26. {
  27. if (numbersArray[i] == numbersArray[i + 1])
  28. {
  29. counter++;
  30. }
  31. else
  32. {
  33. counter = 0;
  34. }
  35. if (counter > maxCounter)
  36. {
  37. maxCounter = counter;
  38. num = numbersArray[i];
  39. }
  40. }
  41. Console.WriteLine(num);
  42. }
  43. }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment