Advertisement
bacco

Most Frequent Number

Jun 2nd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace MostFrequentNumber
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] arr = Console.ReadLine()
  12.                               .Split(' ')
  13.                               .Select(int.Parse).ToArray();
  14.  
  15.             int[] counters = new int[arr.Length];
  16.             int  countMax  = 0;
  17.             int  numMax    = 0;
  18.  
  19.             for (int i = 0; i < arr.Length; i++)
  20.             {
  21.                 for (int j = i; j < arr.Length; j++)
  22.                 {
  23.                     if ( arr[i] == arr[j] )
  24.                     {
  25.                         counters[i]++;
  26.  
  27.                         if (counters[i] > countMax)
  28.                         {
  29.                             countMax = counters[i];
  30.                             numMax = arr[i];
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.             Console.WriteLine(numMax);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement