Spell checker(暴力)

Spell checker

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 20188   Accepted: 7404

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

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

  1 #include<stdio.h>
  2 #include<string.h>
  3 char st[10010][20] ;
  4 struct word_check
  5 {
  6     char src[20] ;
  7     bool flag ;
  8     int cnt , no[100] ;
  9 }word[60];
 10
 11 int k , f;
 12
 13 void check ()
 14 {
 15     int diff ;
 16     int ans ;
 17     for (int i = 0 ; i < f ; i++)
 18         for (int j = 0 ; j < k ; j++)
 19             if (strcmp (word[i].src , st[j]) == 0) {
 20                 word[i].flag = 1 ;
 21             }
 22
 23             for (int i = 0 ; i < f ; i++)
 24                 if (!word[i].flag)
 25                     for (int j = 0 ; j < k ; j++) {
 26                         diff = strlen (word[i].src) - strlen (st[j]) ;
 27                         if (diff == 0) {
 28                             ans = 0 ;
 29                             for (int l = 0 ; st[j][l] != ‘\0‘ ; l++) {
 30                                 if (st[j][l] != word[i].src[l])
 31                                     ans ++ ;
 32                                 if (ans > 1)
 33                                     break ;
 34                             }
 35                             if (ans == 1) {
 36                                 word[i].no [word[i].cnt] = j ;
 37                                 word[i].cnt ++ ;
 38                             }
 39                         }
 40                         else if (diff == 1) {
 41                             int  a = 0 ;
 42                             ans = 0 ;
 43                             for (int l = 0 ; word[i].src[l] != ‘\0‘ ; l++ , a++) {
 44                                 if (st[j][a] != word[i].src[l]) {
 45                                     ans ++ ;
 46                                     a-- ;
 47                                 }
 48                                 if (ans > 1)
 49                                     break ;
 50                             }
 51                             if (ans == 1) {
 52                                 word[i].no[word[i].cnt] = j ;
 53                                 word[i].cnt ++ ;
 54                             }
 55                         }
 56                         else if (diff == -1) {
 57                             int a = 0 ;
 58                             ans = 0 ;
 59                             for (int l = 0 ; st[j][a] != ‘\0‘ ; l++ , a++) {
 60                                 if (st[j][a] != word[i].src[l]) {
 61                                     ans ++ ;
 62                                     l-- ;
 63                                 }
 64                                 if (ans > 1)
 65                                     break ;
 66                             }
 67                             if (ans == 1) {
 68                                 word[i].no[word[i].cnt] = j ;
 69                                 word[i].cnt ++ ;
 70                             }
 71                         }
 72                     }
 73
 74     for (int i = 0 ; i < f ; i++) {
 75         if (word[i].flag) {
 76             printf ("%s is correct\n" , word[i].src) ;
 77         }
 78         else {
 79             printf ("%s:" , word[i].src) ;
 80             for (int j = 0 ; j < word[i].cnt ; j++) {
 81                 printf (" %s" , st[word[i].no[j]]) ;
 82
 83             }
 84             //printf ("%d\n" , word[i].cnt) ;
 85             printf ("\n") ;
 86         }
 87     }
 88 }
 89
 90
 91 int main ()
 92 {
 93   //  freopen ("a.txt" , "r" , stdin) ;
 94     while (~ scanf ("%s" , st[0])) {
 95         k = 0 ;
 96         f = 0 ;
 97         getchar () ;
 98         while (1) {
 99             gets (st[++k]) ;
100             if (strcmp (st[k] , "#") == 0)
101                 break ;
102         }
103         while (1) {
104             gets (word[f].src) ;
105             word[f].cnt = 0 ;
106             f++ ;
107             if (strcmp (word[f - 1].src , "#") == 0)
108                 break ;
109         }
110         f-- ;
111      /*   for (int i = 0 ; i < k ; i++)
112             printf ("%d " , word[i].flag) ;
113         puts ("");
114         for (int i = 0 ; i < f ; i++)
115             puts (word[i].src) ;*/
116         check () ;
117     }
118     return 0 ;
119 }

时间: 2024-10-07 01:49:44

Spell checker(暴力)的相关文章

POJ1035 Spell checker

在做用户查找时 因为要把查找的结果动态加载和显示,所以,那些html元素要由Ajax动态生成.用户打开查找界面时,有系统推荐的用户,而当用户按条件查找后,查找的结果动态加载和显示.所以考虑到用js来搞. 这个for循环就是移除已有的表单.然后根据Ajax请求过来的数据,动态生成新的表单对象.一定要注意j变量从大往小循环,否则,删除div元素后会引起serchResultLenth=serchResult.children.length;长度的变化(这个问题摸索了好久,才搞定,切记) for(va

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total 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 word

POJ1035——Spell checker(字符串处理)

Spell checker DescriptionYou, 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 ab

[ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total 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 word

【POJ】1035 Spell checker

字典树. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <string> 7 using namespace std; 8 9 typedef struct Trie { 10 int in; 11 Trie *next[26]; 12 } Trie;

Spell checker POJ 1035 字符串

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 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 word

poj1035(Spell checker)

题目地址:Spell checker 题目大意: 给你一个关于字符串的字典,让你根据字典里的字符串判断输入字符串的正确性.如果字符串不正确,可以通过以下的操作来输出字符串的可能性:1.可以替换一个字符,2.可以删除一个字符,3.可以添加一个字符.如果满足以上操作,说明都算是字符串的可能性,然后输出. 解题思路: 判断四种情况即可,如果正确直接输出,如果出现1.2.3这几种情况,先将字符串存到一个字符数组里s[N][N].如果全部判断完,没有正确性,输出可能性的字符串. 代码: 1 #includ

POJ 1035 Spell checker (串)

题目大意: 问你后面输入的串能不能通过  加减一个字符,或者替换一个字符变成字典中的串. 思路分析: 直接模拟替换加减的过程. 比较两个串的长度.要相差为1 的时候才能进行模拟. 模拟的过程就是进行一个个的匹配. 发现失配的次数小于等于 1就可以输出. #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <string> #i

poj 1035 Spell checker(暴力判断)

题目链接:http://poj.org/problem?id=1035 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 f