Advertisement
YavorGrancharov

Most_Frequent_Number_II

Oct 13th, 2017
118
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_II
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine()
  11.                 .Split(' ')
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.            
  15.             int freq = 0;
  16.             int count = 0;
  17.             int current = 0;
  18.  
  19.             for (int i = 0; i < arr.Length; i++)
  20.             {
  21.                 count = 0;
  22.                 for (int j = 0; j < arr.Length; j++)
  23.                 {
  24.                     if (arr[i] == arr[j])
  25.                     {
  26.                         count++;
  27.                     }
  28.                 }
  29.                 if (count > current)
  30.                 {
  31.                     current = count;
  32.                     freq = arr[i];
  33.                 }
  34.             }
  35.             Console.WriteLine(freq);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement