Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- int N = int.Parse(Console.ReadLine());
- int[] numbers = new int[N];
- for (int i = 0; i < N; i++)
- {
- numbers[i] = int.Parse(Console.ReadLine());
- }
- int[] frequency = new int[11]; // Array to store the frequency of each number (index 1 to 10)
- foreach (int num in numbers)
- {
- frequency[num]++;
- }
- int maxFrequency = 0;
- int mostFrequentNumber = int.MaxValue;
- for (int i = 1; i <= 10; i++)
- {
- if (frequency[i] > maxFrequency)
- {
- maxFrequency = frequency[i];
- mostFrequentNumber = i;
- }
- else if (frequency[i] == maxFrequency && i < mostFrequentNumber)
- {
- mostFrequentNumber = i;
- }
- }
- Console.WriteLine(mostFrequentNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement