Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace MostFrequentNumber
- {
- class MostFrequentNumber
- {
- public static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int counter = 0;
- int number = 0;
- int maxCounter = 0;
- for (int i = 0; i < numbers.Length; i++)
- {
- for (int j = i+1; j < numbers.Length; j++)
- {
- if (numbers[i] == numbers[j])
- {
- counter++;
- if (counter > maxCounter )
- {
- number = numbers[i];
- maxCounter = counter;
- }
- else
- {
- counter = 0;
- }
- }
- }
- }
- Console.WriteLine(number);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement