http://poj.org/problem?id=1035
来源:互联网 发布:mac rar 多余文件 编辑:程序博客网 时间:2024/06/05 06:47
Spell checker
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 19066 Accepted: 6970
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
#include <iostream>#include <cstdio>#include <cstring>using namespace std;char words[10005][20];int n_words = 0;void replace_word(char *str, int i) { int len = strlen(words[i]); int cnt = 0; for (int j = 0; j < len; j ++) { if (str[j] != words[i][j]) cnt ++; } if (cnt == 1) printf(" %s", words[i]);}void add_word(char *str, int i) { int len = strlen(str); int flag = 1; for (int j = 0; j <= len; j ++) { flag = 1; for (int k = 0; k < strlen(words[i]); k ++) { if (k < j && str[k] != words[i][k]) { flag = 0; break; } else if (k > j && str[k-1] != words[i][k]) { flag = 0; break; } } if (flag) { printf(" %s", words[i]); return ; } }}void delete_word(char *str, int i) { int len = strlen(str); int flag = 1; for (int j = 0; j < len; j ++) { flag = 1; for (int k = 0; k < len; k ++) { if (k < j && str[k] != words[i][k]) { flag = 0; break; } else if (k > j && str[k] != words[i][k-1]) { flag = 0; break; } } if (flag) { printf(" %s", words[i]); return ; } }}int main() { char str[20]; while (scanf("%s", str), str[0] != '#') { strcpy(words[n_words ++], str); } int len; while (scanf("%s", str), str[0] != '#') { int flag = 0; for (int i = 0; i < n_words; i ++) { if (strcmp(str, words[i]) == 0) { printf("%s is correct\n", str); flag = 1; break; } } if (flag) continue; printf("%s:", str); len = strlen(str); for (int i = 0; i < n_words; i ++) { if (len == strlen(words[i])) { replace_word(str, i); } else if (len - 1 == strlen(words[i])) { delete_word(str, i); } else if (len + 1 == strlen(words[i])) { add_word(str, i); } } printf("\n"); }return 0;}
0 0
- http://poj.org/problem?id=1035
- http://poj.org/problem?id=2965
- http://poj.org/problem?id=2075
- http://poj.org/problem?id=1125
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=2406
- http://poj.org/problem?id=1961
- http://poj.org/problem?id=1486
- http://poj.org/problem?id=1062
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=3159
- http://poj.org/problem?id=1201
- http://poj.org/problem?id=3259
- http://poj.org/problem?id=3233
- http://poj.org/problem?id=1273
- http://poj.org/problem?id=3281
- http://poj.org/problem?id=1007
- http://poj.org/problem?id=1840
- php 与nginx配置想内容
- 关于去哪儿网的UI自动化测试脚本
- HDU3768限制最短路(有必经过的点)
- 暑期实训第二课(Arduino上的环境数据采集终端制作<传感器的选择>)
- 指针参数是如何传递内存的?
- http://poj.org/problem?id=1035
- POJ 3468 A Simple Problem with Integers 树状数组 区间修改 区间查询
- 在mac上搭建svn服务器
- C语言continue 和break的用法
- Mysql优化之问题定位
- codeforces 20C Dijkstra?
- 数论寻找等差素数UVA 10650
- samba 服务的搭建
- c# 窗体双缓冲机制