Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
看来只有这种水题才做得到1A,发代码#include <iostream> #include <vector> #include <string> using namespace std; bool check1(string dictopt,string str); bool check2(string dictopt, string str); bool check3(string dictopt, string str); int main() { vector<string> dict; string temp; bool correct = true; while (1) { cin >> temp; if (temp == "#") { break; } dict.push_back(temp); } while (1) { cin >> temp; if (temp == "#") { break; } correct = false; vector<string>::iterator it; for (it = dict.begin(); it != dict.end(); it++) { if (temp == *it) { correct = true; break; } } if (correct == false) { cout << temp << ":"; for (it = dict.begin(); it != dict.end(); it++) { if (check1(*it, temp) || check2(*it, temp) || check3(*it, temp)) { cout << " " << *it; } } }else{ cout << temp << " is correct"; } cout << "\n"; } return 0; } bool check1(string dictopt, string str)//deleting of one letter from the word; { if (dictopt.length() != str.length() + 1) return false; int i,j,k; bool match; for (i = 0; i < dictopt.length(); i++) { match = true; k = 0; for (j = 0; j < dictopt.length(); j++) { if (i == j) continue; if (dictopt[j] != str[k]) { match = false; break; } k++; } if (match) { return true; } } return false; } bool check2(string dictopt, string str)//replacing of one letter in the word with an arbitrary letter; { if (dictopt.length() != str.length()) return false; int i, j; bool match; for (i = 0; i < dictopt.length(); i++) { match = true; for (j = 0; j < dictopt.length(); j++) { if (i == j) continue; if (dictopt[j] != str[j]) { match = false; break; } } if (match) { return true; } } return false; } bool check3(string dictopt, string str)//inserting of one arbitrary letter into the word. { if (dictopt.length()+1 != str.length()) return false; int i, j, k; bool match; for (i = 0; i < str.length(); i++) { match = true; k = 0; for (j = 0; j < str.length(); j++) { if (i == j) continue; if (str[j] != dictopt[k]) { match = false; break; } k++; } if (match) { return true; } } return false; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator