using System.Collections.Generic;
public static void Main()
string sente = "My bike and my book";
Dictionary<string, int> testingDict = TaskUtils.GetWordsRepeatCount(sente);
Dictionary<int, int> testingDict2 = TaskUtils.GetWordsSpanRepeatCount(sente);
Console.WriteLine("Word counter and times that word was used in sentence ");
foreach (KeyValuePair<string, int> kvp in testingDict)
Console.WriteLine("Key = {0} Value = {1}", kvp.Key, kvp.Value);
Console.WriteLine("Word span and number of words with same span ");
foreach (KeyValuePair<int, int> kvp in testingDict2)
Console.WriteLine("Key = {0} Value = {1}", kvp.Key, kvp.Value);
public static class TaskUtils
public static Dictionary<string, int> GetWordsRepeatCount(string text)
Dictionary<string, int> score = new Dictionary<string, int>();
string[] words = text.Split(' ');
foreach (string word in words)
if (score.ContainsKey(word.ToLower()))
score.Add(word.ToLower(), 1);
public static Dictionary<int, int> GetWordsSpanRepeatCount(string text)
Dictionary<int, int> score = new Dictionary<int, int>();
string[] words = text.Split(' ');
foreach (string word in words)
if (score.ContainsKey(word.Length))
score.Add(word.Length, 1);