Question: For the words given to form a dictionary, and then for each input word, there are the following situations:
1. This word is in the dictionary
2. You can delete any letter from the word in the dictionary.
3. This word can be inserted into any letter in the dictionary.
4. Any letter of this word is replaced in the dictionary
Here, we can use string, careful, 10000 dictionary words, 50 query words, and each word cannot exceed 15 characters in length. Therefore, we can determine the brute force traversal of each query word once.
# Include <iostream> # include <string> using namespace STD; string DIC [10005]; // dictionary string ans [10005]; // possible answers: int sum, ans_sum; // Number of dictionary words, possible number of answers string STR; // void imput () {sum = 0; while (CIN> Str) {If (STR = "#") break; DIC [Sum ++] = STR ;}} void print () {cout <STR <':'; for (INT I = 0; I <ans_sum; I ++) cout <''<ans [I]; cout <Endl;} void check () {While (CIN> Str) {If (STR = "#") break; S_sum = 0; bool should_print = true; // whether output is required. The print function is not used after is correct. For (INT I = 0; I <sum; I ++) {If (STR = DIC [I]) {cout <STR <"is correct" <Endl; should_print = false; break ;} else if (DIC [I]. length () = Str. length () {// If the length is equal, one letter may be replaced with int flag = 0; For (Int J = 0; j <DIC [I]. length (); j ++) {If (DIC [I] [J]! = STR [J]) Flag ++;} If (flag = 1) ans [ans_sum ++] = DIC [I];} else if (DIC [I]. length ()-Str. length () = 1) {// insert a letter in STR to compare int flag = 0; For (INT str_l = 0, dic_l = 0; str_l <Str. length () & dic_l <DIC [I]. length ();) {If (STR [str_l] = DIC [I] [dic_l]) str_l ++, dic_l ++; else {dic_l ++; flag ++ ;}} if (! Flag | flag = 1) ans [ans_sum ++] = DIC [I];} else if (Str. length ()-DIC [I]. length () = 1) {// delete a letter int flag = 0; For (INT str_l = 0, dic_l = 0; str_l <Str. length () & dic_l <DIC [I]. length ();) {If (STR [str_l] = DIC [I] [dic_l]) str_l ++, dic_l ++; else {str_l ++; flag ++ ;}} if (! Flag | flag = 1) ans [ans_sum ++] = DIC [I] ;}} if (should_print) print () ;}} int main () {imput (); check (); Return 0 ;}