VPanev

Untitled

Nov 18th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. Int n =int.Parse(Console.ReadLine());
  2. intcounter =1;
  3. intmaxCounter =0;
  4. int[]arr =newint[n];
  5. intnum =0;
  6. for(inti =0;i <n;i++)
  7. {
  8. arr[i]=int.Parse(Console.ReadLine());
  9. }
  10. Array.Sort(arr);
  11. if(n ==1)
  12. {
  13. num =arr[0];
  14. }
  15. for(inti =0;i <n-1;i++)
  16. {
  17. if(arr[i]==arr[i+1])
  18. {
  19. counter++;
  20. }
  21. else
  22. {
  23. counter =0;
  24. }
  25. if(counter >maxCounter)
  26. {
  27. maxCounter =counter;
  28. num =arr[i];
  29. }
  30. }
  31. Console.WriteLine(num);
  32.  
Advertisement
Add Comment
Please, Sign In to add comment