Advertisement
Mirineo

Most Frequent Number

Feb 1st, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. namespace _8.Most_Frequent_Number
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Program
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             int[] inputArray = Console.ReadLine()
  11.                 .Split()
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             int count = 1;
  16.             int mostFreqNum = 0;
  17.             int bestLength = 0;
  18.  
  19.             for (int i = 0; i < inputArray.Length - 1; i++)
  20.             {
  21.                 for (int j = 1; j < inputArray.Length - i; j++)
  22.                 {
  23.                         if (inputArray[i] == inputArray[i + j])
  24.                         {
  25.                             count++;
  26.                         }
  27.  
  28.                         if (count > bestLength)
  29.                         {
  30.                             mostFreqNum = inputArray[i];
  31.                             bestLength = count;
  32.                         }
  33.                 }
  34.  
  35.                 count = 1;
  36.             }
  37.            
  38.                 Console.WriteLine(mostFreqNum);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement