using System.Collections.Generic;
public static void Main()
var words = new List<List<char>>();
var dict = new HashSet<string>();
ParseString(new List<char> {'i', 'r', 'e', 's', 'e', 't', 't', 'h', 'e', 'c', 'o', 'm',
'p', 'u', 't', 'e', 'r', 'i', 't', 's', 't', 'i', 'l',
'l', 'd', 'i', 'd', 'n', 'o', 't', 'b', 'o', 'o', 't'}, 8, dict, words);
foreach(var word in words)
foreach(var letter in word)
words = new List<List<char>>();
ParseString(new List<char> {'j', 'e', 's', 's', 'l', 'o', 'o', 'k', 'e', 'd', 'j', 'u',
's', 't', 'l', 'i', 'k', 'e', 't', 'i', 'm', 'h', 'e',
'r', 'b', 'r', 'o', 't', 'h', 'e', 'r'}, 8, dict, words);
foreach(var word in words)
foreach(var letter in word)
public static void ParseString(List<char> str, int maxLengthInDict, HashSet<string> dict, List<List<char>> words)
var word = new List<char>();
var unrecognizedWord = new List<char>();
for(int i = 0; i < str.Count; i++)
if (dict.Contains(new string(word.ToArray())))
if (unrecognizedWord.Count > 0)
unrecognizedWord.Add('?');
words.Add(new List<char>(unrecognizedWord));
unrecognizedWord = new List<char>();
words.Add(new List<char>(word));
if (word.Count == maxLengthInDict)
unrecognizedWord.Add(word[0]);
if (unrecognizedWord.Count > 0)
words.Add(unrecognizedWord);