BorislavBorisov

Редици.04.02.Most frequent number in string

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