#include #include #include using namespace std; void doit(int n) { cout << n << endl; } string readWord() { string w; cin >> w; return w; } list dictionary; bool testChange(string word1, string word2) { bool change = false; for (int i=0; i < word1.length(); ++i) { if (word1[i] != word2[i]) { if (change) return false; else change = true; } } return true; } bool testInsertion(string longer, string shorter) { int i, j; for (i=0; i0; --j) if (shorter[j-1] != longer[j]) break; return j == i; } bool match(string word1, string word2) { if (word1.length() == word2.length()) return testChange(word1, word2); if (word1.length() - word2.length() == 1) return testInsertion(word1, word2); if (word2.length() - word1.length() == 1) return testInsertion(word2, word1); return false; } void doit(string word) { list matches; for (list::iterator i=dictionary.begin(); i != dictionary.end(); ++i) { if (word == *i) { cout << word << " is correct" << endl; return; } if (match(word, *i)) matches.push_back(*i); } cout << word << ":"; if (!matches.empty()) for (list::iterator i=matches.begin(); i != matches.end(); ++i) cout << " " << *i; cout << endl; } int main() { string word; while (1) { dictionary.clear(); while ((word = readWord()) != "#") dictionary.push_back(word); if (dictionary.empty()) break; while ((word = readWord()) != "#") doit(word); } return 0; }