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 |
一直WA,请大家发点测试数据吧,我实在找不出错误了。我的代码如下:#include <iostream> #include <vector> #include <map> #include <string> using namespace std; typedef multimap<string, string> s2smap_type; s2smap_type s2smap; typedef vector<string> dic_set_type; dic_set_type dic_set; bool Delete(string str1, string str2) { for (size_t i=0; i<str1.size(); ++i) { string temp = str1; temp.erase(i, 1); if (temp == str2) { return true; } } return false; } void Replace(string str1, string str2) { int num=0; for (size_t i=0; i<str1.size(); ++i) { if(str1[i] != str2[i]) { ++num; } } if (num == 1) { s2smap.insert(make_pair(str1, str2)); } } bool ExistStr(string str) { for (size_t i=0; i<dic_set.size(); ++i) { if (dic_set[i] == str) { return true; } } return false; } void Check(string str) { if (ExistStr(str)) { s2smap.insert(make_pair(str, "AAAAAAAAAAAAAAAAAAAA")); return ; } for (dic_set_type::const_iterator iter=dic_set.begin(); iter != dic_set.end(); ++iter) { if ((*iter).size() == str.size() ) { Replace(str, *iter); } else if ((*iter).size() == str.size() - 1 ) { if (Delete(str, *iter)) { s2smap.insert(make_pair(str, *iter)); } } else if ((*iter).size() == str.size() + 1 ) { if (Delete(*iter, str)) { s2smap.insert(make_pair(str, *iter)); } } else { continue; } } } int main() { string dic_string; while (cin >> dic_string && dic_string != "#" && dic_string.size() <= 15) { dic_set.push_back(dic_string); } string input_string; vector<string> vec_input; while (cin >> input_string && input_string != "#" && input_string.size() <= 15) { vec_input.push_back(input_string); } for (size_t i=0; i<vec_input.size(); ++i) { Check(vec_input[i]); } for (size_t i=0; i<vec_input.size(); ++i) { if (s2smap.find(vec_input[i]) == s2smap.end()) {// none cout << vec_input[i] << ":" << endl; } else { s2smap_type::const_iterator iter_ = s2smap.find(vec_input[i]); if(iter_ != s2smap.end() && iter_->second == "AAAAAAAAAAAAAAAAAAAA") { cout << vec_input[i] << " is correct" << endl; continue; } pair<s2smap_type::const_iterator, s2smap_type::const_iterator> s2spair; s2spair = s2smap.equal_range(vec_input[i]); cout << vec_input[i] << ":"; for (s2smap_type::const_iterator iter=s2spair.first; iter != s2spair.second; ++iter) { cout << " " << iter->second; } cout << endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator