-->
当前位置:首页 > 题库

PROGRAMMING:Spell Checker

Luz5年前 (2021-05-10)题库916
This question is about automatic spelling correction. Studies have shown that the majority of typing errors are caused by (let's assume the dictionary contains the word "these"):
1. Omitting one letter, e.g., the input word is "thse".
2. Adding anextra letter, e.g., the input word is "thesce".
3. Mistyping one letter, e.g., the input word is "thise".
4. Transposing two adjacent letters, e.g., the input word is "tehse".
With the aid of a dictionary, word processing systems can often detect and automatically correct these kinds ofspelling errors.
The Problem:
You are to write a program that recognizes the four kinds oferrors described above.
### The Input:
The first input line contains an integer d (1 ≤ d ≤ 100) indicating the number of words in the dictionary. Each ofthe following d input lines contains a dictionary word. Assume these words start in column 1, contain at least 1 and at most 15 lowercase letters, and contain no other characters.
Following the dictionary words (i.e., the next input line), there is an integer n (n ≥ 1) indicating the number ofwords to be spell checked. Each ofthe following n input lines contains a word. These words also start in column 1, contain at least 1 and at most 15 lowercase letters, and contain no other characters.
### The Output:
Print each input word to be spell checked. Then, if the word is in the dictionary, print CORRECT. If the word is not in the dictionary, then find each word in the dictionary (in the order provided in the dictionary) for which the given input word might be a misspelling, and print the appropriate message from the following list:
ONE LETTER OMITTED FROMword
ONE LETTER ADDED TOword
ONE LETTER DIFFERENT FROMword
TWO LETTERS TRANSPOSED INword
where word is a dictionary word. If the input word is not CORRECT and none of the above messages apply, then print UNKNOWN.
Note that two or more of the above messages might be applicable to an input word, and that one message might apply for more than one dictionary word. Note, however, that for a given input word and given dictionary word, at most one of the above messages apply. For each input word, you are to process the dictionary words in the order provided in the input and print all messages that are valid.
Leave a blank line after the output for each input word. Follow the format illustrated in Sample Output.
###Input example:
```in
seven
ali
thru
tu
funfunfun
the
tuh
th
three
ali
thu
orooji
```
###Output example:
```out
ali
CORRECT
thu
ONE LETTER OMITTED FROM thru
ONE LETTER ADDED TO tu
ONE LETTER DIFFERENT FROM the
TWO LETTERS TRANSPOSED IN tuh
ONE LETTER ADDED TO th
orooji
UNKNOWN
```







answer:If there is no answer, please comment