BorislavBorisov

Редици.04.03.Most frequent number in string array

Oct 31st, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. class LongestEqualSubsequence
  4. {
  5.     static string[] array = { "D", "F", "G", "D", "F", "D", "A", };
  6.     static void Main()
  7.     {
  8.         int appearance = 1, bestAppearance = 0;
  9.         FindMostFrequant(appearance, bestAppearance);
  10.     }
  11.  
  12.     static void FindMostFrequant(int appearance, int bestAppearance)
  13.     {
  14.         int value = 0;
  15.         List<string> list = new List<string>();
  16.  
  17.         for (int i = 0; i < array.Length; i++)
  18.         {
  19.             if (list.Contains(array[i]))
  20.             {
  21.                 continue;
  22.             }
  23.             for (int j = i + 1; j < array.Length; j++)
  24.             {
  25.                 if (array[i] == array[j])
  26.                 {
  27.                     appearance++;
  28.                     if (bestAppearance < appearance)
  29.                     {
  30.                         bestAppearance = appearance;
  31.                         value = i;
  32.                     }
  33.                 }
  34.             }
  35.             appearance = 1;
  36.             list.Add(array[i]);
  37.         }
  38.         Console.WriteLine("Best times -> " + bestAppearance);//3
  39.         Console.WriteLine("Value -> " + array[value]);//D
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment