/* * A tiny T9 predictive-text demo. * * Students should fill in AddPrefixesToPredictions and PrintPredictions. */ #include #include #include #include using std::cout; using std::endl; using std::map; using std::string; using std::vector; const map letters_to_keys = { {'a', '2'}, {'b', '2'}, {'c', '2'}, {'d', '3'}, {'e', '3'}, {'f', '3'}, {'g', '4'}, {'h', '4'}, {'i', '4'}, {'j', '5'}, {'k', '5'}, {'l', '5'}, {'m', '6'}, {'n', '6'}, {'o', '6'}, {'p', '7'}, {'q', '7'}, {'r', '7'}, {'s', '7'}, {'t', '8'}, {'u', '8'}, {'v', '8'}, {'w', '9'}, {'x', '9'}, {'y', '9'}, {'z', '9'}, }; map> predictions; // global prediction map void AddPrefixesToPredictions(const string& word) { (void) word; // TODO: Build up the T9 key prefix for this word one letter at a time. // For each prefix, add word to predictions[prefix]. } void PrintPredictions() { // TODO: Loop over every pair in predictions. // Print the key prefix, then every predicted word for that prefix. } void BuildPredictions(const vector& words) { predictions.clear(); for (const string& word : words) { AddPrefixesToPredictions(word); } } int main() { const vector words = { "bat", "cat", "catalog", "dog", "door", "fish", "hello", "help", "home", "good", "gone", "world", }; BuildPredictions(words); PrintPredictions(); return 0; }