Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class MostFrequentNumber
- {
- static void Main()
- {
- var seqNums = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] counts = new int[seqNums.Max() + 1];
- foreach (var num in seqNums)
- {
- counts[num]++;
- }
- var maxInCounts = new List<int>();
- int maxNuminCounters = counts.Max();
- for (int i = 0; i < counts.Length; i++)
- {
- if (counts[i] == counts.Max())
- {
- maxInCounts.Add(i);
- }
- }
- for (int i = 0; i < seqNums.Length; i++)
- {
- if (maxInCounts.Contains(seqNums[i]))
- {
- Console.WriteLine(seqNums[i]);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment