Advertisement
n4wn4w

C# zadacha Sirma

May 2nd, 2015
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.35 KB | None | 0 0
  1. string allLangs = "Started from the bottom now we're here Started from the bottom now my whole team fucking here Started from the bottom now we're here".ToUpper();
  2.             string[] langs = allLangs.Split(new char[] { ',', ';', ' ','.','!','\'','"','$','?','+' },
  3.                 StringSplitOptions.RemoveEmptyEntries);
  4.            
  5.             string kurr = string.Join("", langs);
  6.             char[] letters = kurr.ToCharArray();
  7.            
  8.             Dictionary<char, int> dict = new Dictionary<char, int>();
  9.  
  10.             foreach (char t in letters)
  11.             {
  12.                 if (!dict.ContainsKey(t))
  13.                 {
  14.                     dict.Add(t, 1);
  15.                 }
  16.                 else
  17.                 {
  18.                     dict[t]++;
  19.                 }
  20.             }
  21.            
  22.  
  23.             dict = dict.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
  24.  
  25.            
  26.             Console.WriteLine("\nLetter occurence table:\n{0}\n",string.Join("\n",
  27.                 dict.Select(x => string.Format(@"'{0}' -> {1,2} {2}", x.Key, x.Value,new string('#',x.Value))).ToArray().Reverse()));
  28.  
  29.  
  30.  
  31. /////////////////////////////////////// 2 reshenie //////////////////////////////////
  32.  
  33.  
  34.  
  35.             string allLangs = @"Started from the bottom now we're here
  36.            Started from the bottom now my whole team fucking here
  37.            Started from the bottom now we're here".ToUpper();
  38.  
  39.             string[] langs = allLangs.Split(new char[] { ',', ';', ' ', '.', '!', '\'', '"', '$', '?', '+' },
  40.                 StringSplitOptions.RemoveEmptyEntries);
  41.  
  42.             string kurr = string.Join("", langs);
  43.             char[] letters = kurr.ToCharArray();
  44.  
  45.             Dictionary<char, int> dict = new Dictionary<char, int>();
  46.  
  47.             foreach (char t in letters)
  48.             {
  49.                 if (!dict.ContainsKey(t))
  50.                 {
  51.                     dict.Add(t, 1);
  52.                 }
  53.                 else
  54.                 {
  55.                     dict[t]++;
  56.                 }
  57.             }
  58.  
  59.  
  60.             List<KeyValuePair<char, int>> myList = dict.ToList();
  61.  
  62.             myList.Sort(
  63.                 delegate(KeyValuePair<char, int> firstPair,
  64.                 KeyValuePair<char, int> nextPair)
  65.                 {
  66.                     return firstPair.Value.CompareTo(nextPair.Value);
  67.                 }
  68.             );
  69.  
  70.             myList.Reverse();
  71.  
  72.             var k = 0;
  73.             foreach (var dr in myList)
  74.             {
  75.                 k++;
  76.                 if (k >= 11) break;
  77.                 Console.WriteLine("{0} = {1,3} -> {2,1}",dr.Key , dr.Value , new string('#', dr.Value));
  78.             }
  79.  
  80.  
  81.  
  82. ////////////////////// 3 reshenie vzimane samo na glavnite bukvi i  razdelqne s REGEX addvane v LIST  //////////////////////////////////////////
  83.  
  84.  
  85.  
  86.   string allLangs = @"Started From The Bottom Now We'Re Here
  87.            Started From The Bottom Now My Whole Team Fucking Here
  88.            Started From The Bottom Now We'Re Here";
  89.  
  90.             string regex = @"[A-Z]";
  91.  
  92.  
  93.             MatchCollection separatorsInSentance = Regex.Matches(allLangs, regex);
  94.             List<object> LList = new List<object>();
  95.             foreach (var s in separatorsInSentance)
  96.             {
  97.                 LList.Add(s);
  98.             }
  99.  
  100.            
  101.             string kurr = string.Join("", LList);
  102.             char[] letters = kurr.ToCharArray();
  103.  
  104.  
  105.  
  106.             Dictionary<char, int> dict = new Dictionary<char, int>();
  107.  
  108.             foreach (char t in letters)
  109.             {
  110.                 if (!dict.ContainsKey(t))
  111.                 {
  112.                     dict.Add(t, 1);
  113.                 }
  114.                 else
  115.                 {
  116.                     dict[t]++;
  117.                 }
  118.             }
  119.  
  120.  
  121.             List<KeyValuePair<char, int>> myList = dict.ToList();
  122.  
  123.             myList.Sort(
  124.                 delegate(KeyValuePair<char, int> firstPair,
  125.                 KeyValuePair<char, int> nextPair)
  126.                 {
  127.                     return firstPair.Value.CompareTo(nextPair.Value);
  128.                 }
  129.             );
  130.  
  131.             myList.Reverse();
  132.  
  133.             var k = 0;
  134.             foreach (var dr in myList)
  135.             {
  136.                 k++;
  137.                 if (k >= 11) break;
  138.                 Console.WriteLine("{0} = {1,3} -> {2,1}",dr.Key , dr.Value , new string('#', dr.Value));
  139.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement