简单题
View Code
#include <iostream> #include <string> #include <cmath> using namespace std; const int maxn = 10001; string dictionary[maxn], checking; int total; bool common(string a, string b) { int i, different; string t; bool first; if (abs(int(a.length() - b.length())) > 1) return false; if (a.length() == b.length()) { different = 0; for (i = 0; i < a.length(); i++) if (a[i] != b[i]) different++; if (different > 1) return false; return true; } if (a.length() > b.length()) { t = a; a = b; b = t; } first = true; i = 0; while (i < a.length()) { if (a[i] != b[i]) { if (first) b.erase(i, 1); else return false; first = false; } else i++; } return true; } int main() { int i; bool correct; //freopen("t.txt", "r", stdin); i = 0; while (true) { getline(cin, dictionary[i]); if (dictionary[i] == "#") break; i++; } total = i; while (true) { getline(cin, checking); if (checking == "#") break; cout << checking; correct = false; for (i = 0; i < total; i++) if (checking == dictionary[i]) { cout << " is correct"; correct = true; break; } if (!correct) { cout << ":"; for (i = 0; i < total; i++) if (common(checking, dictionary[i])) { cout << " "; cout << dictionary[i]; } } cout << endl; } return 0; }