Spell checker poj 1035 (串的练习)
来源:互联网 发布:卡证制作软件 编辑:程序博客网 时间:2024/06/05 14:15
大致题意:
输入一部字典,输入若干单词
1、 若某个单词能在字典中找到,则输出corret
2、 若某个单词能通过 变换 或 删除 或 添加一个字符后,在字典中找得到,则输出这些单词,输出顺序根据 输入的那部字典的字典序
输入一部字典,输入若干单词
1、 若某个单词能在字典中找到,则输出corret
2、 若某个单词能通过 变换 或 删除 或 添加一个字符后,在字典中找得到,则输出这些单词,输出顺序根据 输入的那部字典的字典序
3、 若某个单词无论操作与否都无法在字典中找得到,则输出空
#include <cstdio>#include <cstring>#include<iostream>using namespace std;char dict[10001][16];char word[51][16];int DictNum=0;int WordNum=0;void Input(void);bool Change(char *word,char *dir);bool Del(char *word,char *dict);bool Add(char *word,char *dict);void Input(void){ while(cin>>dict[DictNum] && dict[DictNum++][0]!='#'); while(cin>>word[WordNum] && word[WordNum++][0]!='#'); --DictNum; --WordNum; return;}bool Change(char *word,char *dict){ int dif=0; while(*word) { if(*(word++) != *(dict++)) { dif++; if(dif>1) return false; } } 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(){ Input(); int *Dictlen=new int[DictNum]; for(int i=0; i<DictNum; ++i) Dictlen[i]=strlen(dict[i]); for(int i=0; i<WordNum; ++i) { int *address=new int[DictNum]; int pa=0; bool flag=false; int len=strlen(word[i]); for(int k=0; k<DictNum; ++k) { if(Dictlen[k]==len) { if(!strcmp(word[i],dict[k])) { flag=true; break; } else if(Change(word[i],dict[k])) { address[pa++]=k; } } else if(len-Dictlen[k]==1) { if(Del(word[i],dict[k])) address[pa++]=k; } else if(Dictlen[k]-len==1) { if(Del(dict[k],word[i])) address[pa++]=k; } } if(flag) cout<<word[i]<<" is correct"<<endl; else { cout<<word[i]<<":"; for(int j=0; j<pa; ++j) cout<<' '<<dict[address[j]]; cout<<endl; } delete address; } return 0;}
阅读全文
0 0
- Spell checker poj 1035 (串的练习)
- poj-1035--Spell checker-串
- POJ 1035 Spell checker 串
- poj-1035-Spell checker
- poj 1035 Spell checker
- Poj 1035 --Spell checker
- Spell checker--POJ 1035
- 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
- poj 1035 Spell checker
- oracle字段根据字符串拆分
- poj 2352 && hdu 1541 Stars(树状数组)
- 温度传感器 DS18B20
- Browse the filesystem链接打不开
- cacti中snmp的应用
- Spell checker poj 1035 (串的练习)
- elasticsearch学习总结(二) 集群数据分配
- [SIM]如何修改使得系统语言不会随着 第一次插入的SIM卡而改变
- 数位dp
- 博弈论——sg函数模板
- Android 流式布局 + 搜索记录,包括多数据本地存储
- EditText点击事件:弹出时间框
- java简单坦克大战制作代码
- 亚信前端实习生面试记录