poj_1035 串
来源:互联网 发布:青岛知行国际 虚假 编辑:程序博客网 时间:2024/06/05 02:16
对每个给定的词,在字典中查是否equal,或者是否可以通过replace、insert、delete构成,若可以,记录。水题。
code:
<span style="font-size:18px;">#include <iostream>#include <fstream>using namespace std;char dict[10001][16];char word[51][16];int dictNum = 0;int wordNum = 0;int dictLen = 0;bool replace(char *word, char *dict){int dif = 0;while (*word){if (*(word++) != *(dict++)){dif++;if (dif > 1)return false;}}return true;}bool insert(char *word,char *dict){int dif = 0;while (*word){if (*(word) != *(dict)){dict++;dif++;if (dif > 1)return false;}else{word++;dict++;}}return true;}bool del(char *word,char *dict){int dif = 0;while (*word){if (*(word) != *(dict)){word++;dif++;if (dif > 1)return false;}else{word++;dict++;}}return true;}int main(){int i, j;//ifstream in("input.txt");//input datawhile (cin >> dict[dictNum] && dict[dictNum++][0] != '#');while (cin >> word[wordNum] && word[wordNum++][0] != '#');dictNum--;wordNum--;int *dictLen = new int[dictNum];for (i = 0; i < dictNum; i++){dictLen[i] = strlen(dict[i]);}//handle:delete\replace\insertfor (i = 0; i < wordNum; i++) {int *loc = new int[dictNum];//the change locationint ploc = 0;//change numbersbool flag = false;//now the dict does not have the wordint wordLen = strlen(word[i]);for (j = 0; j < dictNum; j++){if (wordLen == dictLen[j])//replace or equal{if (!strcmp(word[i], dict[j]))//equal{flag = true;break;}else if (replace(word[i],dict[j]))//replace{loc[ploc++] = j;}}else if (wordLen == dictLen[j]-1)//insert{if (insert(word[i], dict[j]))loc[ploc++] = j;}else if (wordLen == dictLen[j] + 1)//delete{if (del(word[i], dict[j]))loc[ploc++] = j;}}//outputif (flag){cout << word[i] << " is correct" << endl;}else{cout << word[i] << ": ";for (j = 0; j < ploc; j++){cout << dict[loc[j]] << " ";}cout << endl;}}//system("pause");return 0;}</span>
0 0
- poj_1035 串
- poj_1035
- POJ_1035题解
- [POJ_1035]Spell checker
- poj_1035 Spell checker(字符串处理)
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- 串
- Android:的Bitmap进行ClipPath存在锯齿
- 修改IntelliJ IDEA的类文件模板
- opencv系列之一 利用透视变换实现图像的俯视图(正视图)
- 通过代码setTextColor,改变不同状态下的textColor
- 中日电脑相关词汇(超详版)
- poj_1035 串
- XMPPFramework 介绍
- Hibernate Session的Flush模式
- net_device
- Netbeans XDebug环境搭建
- java 选择文件夹 JFileChooser
- XMPPFramework 实现IM客户端 (1)
- Http Session 详解
- hdu4333----Revolving Digits