poj 1035(Wrong Answer)
2012-04-07 21:56
309 查看
这次是Wrong Answer...
自己测数据倒是对
太菜了。。。
自己测数据倒是对
太菜了。。。
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; //#define _debbug //全局数据 vector<string> dic(100000,"") ; vector<string> checkwords(5000,"") ; vector<string> alphabet(26) ; bool found(string temp) { int testnum = 0; for (string testdic = dic[testnum] ; testdic != "" ; testdic = dic[testnum]) { if (temp == testdic) { return true ; } else testnum++ ; } return false ; } void match() { int ceshi = 0 ; for (string testdic = checkwords[ceshi] ; testdic != "" ; testdic = checkwords[ceshi]) { if (found(testdic)) { cout<<testdic<<" is correct"<<endl ; ceshi++ ; continue ; } else { cout<<testdic<<": " ; //情况一,删除一个字符 for (int i = 0 ; i < testdic.size() ; ++i) { string deletemp = testdic ; deletemp.erase(i,1) ; if (found(deletemp)) { cout<<deletemp<<" " ; } } //情况二,替换其中一个字符 for (int j = 0 ; j < testdic.size() ; ++j) { string replacetemp = testdic ; for (int jj = 0 ;jj < 26 ; ++jj) { replacetemp.replace(j,1,alphabet[jj]) ; if (found(replacetemp)) { cout<<replacetemp<<" " ; } } } //情况三,插入其中一个字符 for (int k = 0 ; k <= testdic.size(); ++k) { string inserttemp = testdic ; for (int kk = 0 ;kk < 26 ; ++kk) { string inserttemp = testdic ; inserttemp.insert(k,alphabet[kk]) ; if (found(inserttemp)) { cout<<inserttemp<<" " ; } } } ceshi++ ; cout<<endl ; } } } int main() { //重定向 #ifdef _debbug streambuf *backup1; ifstream fin; fin.open ("F:\\input.txt" ,ios::in ); backup1 = cin.rdbuf() ; // back up cin's streambuf cin.rdbuf( fin.rdbuf() ) ; // assign file's streambuf to cin #endif // alphabet[0] = "a" ;alphabet[1] = "b" ;alphabet[2] = "c" ;alphabet[3] = "d" ;alphabet[4] = "e" ;alphabet[5] = "f" ;alphabet[6] = "g" ; alphabet[7] = "h" ;alphabet[8] = "i" ;alphabet[9] = "j" ;alphabet[10] = "k" ;alphabet[11] = "l" ;alphabet[12] = "m" ;alphabet[13] = "n" ; alphabet[14] = "o" ;alphabet[15] = "p" ;alphabet[16] = "q" ;alphabet[17] = "r" ;alphabet[18] = "s" ;alphabet[19] = "t" ;alphabet[20] = "u" ; alphabet[21] = "v" ;alphabet[22] = "w" ;alphabet[23] = "x" ;alphabet[24] = "y" ;alphabet[25] = "z" ; //数据初始化 dic.reserve(10000) ; checkwords.reserve(50) ; string temp = "" ; int cnt = 0 ; while (temp != "#") { cin >> temp ; if (temp == "#") break ; dic[cnt++] = temp ; } int start = 0 ; temp = "" ; while (temp != "#") { cin >> temp ; if (temp == "#") break ; checkwords[start++] = temp; } //执行函数 //匹配 match() ; //输出结果 /* for (int kk= 0 ;kk <26 ; kk++) { cout <<endl << alphabet[kk]; } */ //解除重定向关闭文件 #ifdef _debbug cin.rdbuf(backup1) ; // restore cin's original streambuf fin.close(); #endif return 0 ; }
相关文章推荐
- poj1035 数据结构串(1)
- poj 1035
- poj 1035 Spell checker
- POJ 1035 Spell checker
- POJ 1573 && hdu 1035 Robot Motion【简单模拟】
- POJ 1035
- POJ Spell checker(1035)-字符串处理
- poj 1035
- POJ1035-Spell checker(java版)
- poj 1035 Spell checker trie树+快排
- http://poj.org/problem?id=1035
- 【Q】【POJ 1035】
- POJ 1035 Spell checker
- POJ 1035 Spell checker(字符串处理)
- Spell checker POJ 1035 字符串
- poj 1035 Spell checker
- POJ 1035
- poj 1035 串
- POJ1035-Spell checker
- Spell checker poj1035