POJ 1035 Spell checker (串)
2014-07-21 16:04
351 查看
题目大意:
问你后面输入的串能不能通过 加减一个字符,或者替换一个字符变成字典中的串。
思路分析:
直接模拟替换加减的过程。
比较两个串的长度。要相差为1 的时候才能进行模拟。
模拟的过程就是进行一个个的匹配。
发现失配的次数小于等于 1就可以输出。
问你后面输入的串能不能通过 加减一个字符,或者替换一个字符变成字典中的串。
思路分析:
直接模拟替换加减的过程。
比较两个串的长度。要相差为1 的时候才能进行模拟。
模拟的过程就是进行一个个的匹配。
发现失配的次数小于等于 1就可以输出。
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <string> #include <map> #define maxn 10005 using namespace std; char str[maxn][20]; string tmp; map <string,bool>mymap; int main() { while(scanf("%s",str[0])!=EOF) { mymap.clear(); tmp=str[0]; mymap[tmp]=true; int i=1; while(scanf("%s",str[i]) && str[i][0]!='#') { tmp=str[i]; mymap[tmp]=true; i++; } char txt[20]; while(scanf("%s",txt) && txt[0]!='#') { tmp=txt; if(mymap[tmp])printf("%s is correct\n",txt); else { printf("%s:",txt); int l=strlen(txt); for(int j=0;j<i;j++) { int len=strlen(str[j]); if(l+1==len) { int cnt=0; int p=0,k=0; while(p<l && k<len) { if(txt[p]==str[j][k]) p++,k++; else { cnt++; k++; } } if(cnt<=1 && p==l)printf(" %s",str[j]); } if(l==1+len) { int cnt=0; int p=0,k=0; while(p<len && k<l) { if(str[j][p]==txt[k])p++,k++; else { cnt++; k++; } } if(cnt<=1 && p==len)printf(" %s",str[j]); } if(l==len) { int cnt=0; for(int k=0;k<len;k++)if(txt[k]!=str[j][k])cnt++; if(cnt==1)printf(" %s",str[j]); } } puts(""); } } } return 0; }
相关文章推荐
- 字符串 模拟 Spell checker (poj 1035)
- Spell checker (poj 1035 字符串)
- POJ 1035 Spell checker 查找单词
- POJ1035 Spell-checker(哈希,串处理)
- [ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)
- POJ 1035-Spell checker(字符串)
- poj 1035 Spell checker(字符串处理)
- POJ 1035 Spell checker (字符串模拟)
- POJ 1035 Spell checker 字符串容错检查
- poj 1035 (Spell checker )
- POJ 1035 Spell checker【字符串处理】
- poj 1035 Spell checker 字符串,暴力
- POJ训练计划1035_Spell checker(串处理/暴力)
- POJ 1035 Spell checker(字符串简单匹配)
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
- poj 1035 Spell checker(暴力判断)
- POJ-1035 Spell checker 暴力
- Spell checker--POJ 1035
- Spell checker poj1035
- POJ 1035 Spell checker (模拟)