Advertisement
martinvalchev

Most_Frequent_Number

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