poj 1035 Spell checker
2015-06-16 12:37
302 查看
Spell checker
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.
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.
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
Sample Output
Source
Northeastern Europe 1998
一道模拟题。。随便搞都可以过~
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 20588 | Accepted: 7588 |
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.
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.
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
i is has have be my more contest me too if award # me aware m contest hav oo or i fi mre #
Sample Output
me is correct aware: award m: i my me contest is correct hav: has have oo: too or: i is correct fi: i mre: more me
Source
Northeastern Europe 1998
一道模拟题。。随便搞都可以过~
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h> #include <stdlib.h> #include <math.h> #include <vector> #include <map> #include <set> #include <queue> #include <stack> using namespace std; char word[10010][20]; int len[10010]; char tmp[233]; int fab(int a,int b) { if(a-b<=1&&b-a<=1) return 1; else return 0; } int main() { int top=1; while(scanf("%s",word[top])) { if(word[top][0]=='#') break; len[top]=strlen(word[top]); top++; } top--; while(scanf("%s",tmp)) { if(tmp[0]=='#') break; int flag=0; for(int i=1;i<=top;i++) { if(strcmp(tmp,word[i])==0) { flag=1; break; } } if(flag==1) { cout<<tmp<<" is correct"<<endl; continue; } cout<<tmp<<":"; int leng=strlen(tmp); for(int i=1;i<=top;i++) { if(fab(leng,len[i])) { int cnt=0; int pos; for(int j=0;j<leng;j++) { if(tmp[j]!=word[i][j]) { pos=j; cnt++; break; } } if(len[i]>leng) { for(int j=pos;j<leng;j++) { if(tmp[j]!=word[i][j+1]) { cnt++; break; } } } else if(len[i]<leng) { for(int j=pos+1;j<leng;j++) { if(tmp[j]!=word[i][j-1]) { cnt++; break; } } } else { for(int j=pos+1;j<leng;j++) { if(tmp[j]!=word[i][j]) { cnt++; break; } } } if(cnt<=1) { cout<<" "<<word[i]; } } } cout<<endl; } return 0; }
相关文章推荐
- coredata基础用法1(附coredata demo)
- C中的几个小知识点
- ProtocolBuffer for Objective-C 运行环境配置(真正测试过的)
- [8] MQTT,mosquitto,Eclipse Paho---MQTT消息格式之SUBSCRIBE(消息订阅)消息分析
- Android项目javadoc时出现的几个错误解决
- [Erlang].erl文件的一生
- Error inflating class linearlayout
- Python学习(二)---使用list和tuple
- 如何看懂代码
- 在你的Android App中支持多主题
- fedora10 安装NFS服务 ARM端挂载
- [Swust 549]--变位词(vector水过)
- 一站式解决,Android 拍照 图库的各种问题
- hdu 1035 (usage of sentinel, proper utilization of switch and goto to make code neat)
- nodejs的交叉(跨平台)编译(to android)
- 动态加载jQuery的方法
- Fresco介绍 - 一个新的android图片加载库
- 百度LBS jar包之间冲突
- OC中方法与函数的区别(转)
- 兼容性要点