13
for (int i = 0; i < 26; i++) {24
root = new trii('\0');27
void insert(string str, trii *node) {28
if (str.size() == 0) {29
node->isTerminal = true;32
int index = str[0] - 'a';33
if (node->dict[index] == NULL) {34
node->dict[index] = new trii(str[0]);36
insert(str.substr(1), node->dict[index]);39
string find(string str, trii *node, string pre) {40
if (node->isTerminal == true) {43
int index = str[0] - 'a';44
if (str.size() == 0 || node->dict[index] == NULL) {47
return find(str.substr(1), node->dict[index], pre + str[0]);50
string replaceWith(string word, trii *node) {51
string temp = find(word, node, "");59
string replaceWords(vector<string> &dictionary, string sentence) {61
for (int i = 0; i < dictionary.size(); i++) {62
t->insert(dictionary[i], t->root);64
string ans = sentence;66
for (int i = 0; i < ans.size(); i++) {68
while (i < ans.size() && ans[i] != ' ') {73
sentence += t->replaceWith(word, t->root) + " ";