poj 1035 Spell checker
来源:互联网 发布:淘宝哪家卖外设保真 编辑:程序博客网 时间:2024/05/17 05:18
Spell checker
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 20588 Accepted: 7588
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
一道模拟题。。随便搞都可以过~
#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;}
0 0
- 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
- POJ 1035 Spell checker
- poj 1035 Spell checker
- POJ 1035 Spell checker
- Python学习(二)---使用list和tuple
- 如何看懂代码
- vsftpd详细配置说明
- Linux网络编程socket错误分析
- C中的几个小知识点
- poj 1035 Spell checker
- How-to: Enbale HMaster HA(high availability) and High Available Reads
- MFC操作SQlite,打开数据库路径存在中文,解决方案
- 【绿皮】新GRE填空补充练习题Exercise3
- 设置FTP账号
- webservice java实现
- Mac office 2011 打开word有中文乱码问题解决
- MFC的对话框工具栏、状态栏、和菜单栏的编辑
- SAT数学:考试允许使用计算器