[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)
来源:互联网 发布:毛丝鼠淘宝 编辑:程序博客网 时间:2024/05/19 09:50
Spell checker
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 18693 Accepted: 6844
Description
You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms.
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:
?deleting of one letter from the word;
?replacing of one letter in the word with an arbitrary letter;
?inserting of one arbitrary letter into the word.
Your task is to write the program that will find all possible replacements from the dictionary for every given word.
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:
?deleting of one letter from the word;
?replacing of one letter in the word with an arbitrary letter;
?inserting of one arbitrary letter into the word.
Your task is to write the program that will find all possible replacements from the dictionary for every given word.
Input
The first part of the input file contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character '#' on a separate line. All words are different. There will be at most 10000 words in the dictionary.
The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character '#' on a separate line. There will be at most 50 words that are to be checked.
All words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.
The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character '#' on a separate line. There will be at most 50 words that are to be checked.
All words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.
Output
Write to the output file exactly one line for every checked word in the order of their appearance in the second part of the input file. If the word is correct (i.e. it exists in the dictionary) write the message: " is correct". If the word is not correct then write this word first, then write the character ':' (colon), and after a single space write all its possible replacements, separated by spaces. The replacements should be written in the order of their appearance in the dictionary (in the first part of the input file). If there are no replacements for this word then the line feed should immediately follow the colon.
Sample Input
iishashavebemymorecontestmetooifaward#meawaremcontesthavooorifimre#
Sample Output
me is correctaware: awardm: i my mecontest is correcthav: has haveoo: tooor:i is correctfi: imre: more me
Source
Northeastern Europe 1998
输入词典中的单词,再输入需要查找的单词,查找到有四种方法:
1. 该单词存在词典中
2.该单词通过替换任何一个字母后存在于词典中(如果有多个,按词典序输出)
3.该单词通过删除任何一个字母后存在于词典中
4.该单词通过增加一个字母后存在于词典中
做本题遇到的问题:
char dic[ ] [ ] 存词典, char wor[] [] 存待查找的单词。
在判断单词是否能通过删除一个字母后存在于词典中时,因为函数传的是指针,而函数中又把字母的顺序移动了,这就造成把原单词给改变了,这个错误太致命了。。。其实判断上面说的后两种情况可以通过指针移动,判断不匹配的个数,单词的指针为i, 词典某个单词的指针为j , 当它们的字母相同时,i++,j++,不同时, 就让单词长度长的那个指针+1,mistake+1另一个不动,mistake的个数不能大于1,(因为判断的两个单词长度之差的绝对值不会大于1).
还有有个地方严重超时,下面代码:
直接操作就可以:
代码:
0 0
- [ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)
- [ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)
- POJ 1035 Spell checker 查找单词
- POJ 1035 Spell checker 【字符串暴力查找】
- poj 1035 Spell checker &nyoj 162 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
- Spring MVC入门实例
- Java常用线程池使用说明
- [ACM] POJ 1936 All in All (查找,一个串是否在另一个串中)
- 黑马程序员——抽象类能否继承普通类与接口能否继承普通类
- TCP学习(3)--TCP释放连接的过程(四次挥手)
- [ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)
- 产品项目生命周期中的各种文档
- CodeForces 4D-Mysterious Present
- hdu3549Flow Problem 最大流模板水题
- ios测试的时候出现错误
- JavaScript知识点总结-2
- 将字符串写入文本文件
- 大数据的痛点
- [ACM] poj 1064 Cable master (二分查找)