Advertisement
debono

Untitled

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