Poj 1035 spell checker

Source: Internet
Author: User

Question: For the words given to form a dictionary, and then for each input word, there are the following situations:

1. This word is in the dictionary

2. You can delete any letter from the word in the dictionary.

3. This word can be inserted into any letter in the dictionary.

4. Any letter of this word is replaced in the dictionary

Here, we can use string, careful, 10000 dictionary words, 50 query words, and each word cannot exceed 15 characters in length. Therefore, we can determine the brute force traversal of each query word once.

 

# Include <iostream> # include <string> using namespace STD; string DIC [10005]; // dictionary string ans [10005]; // possible answers: int sum, ans_sum; // Number of dictionary words, possible number of answers string STR; // void imput () {sum = 0; while (CIN> Str) {If (STR = "#") break; DIC [Sum ++] = STR ;}} void print () {cout <STR <':'; for (INT I = 0; I <ans_sum; I ++) cout <''<ans [I]; cout <Endl;} void check () {While (CIN> Str) {If (STR = "#") break; S_sum = 0; bool should_print = true; // whether output is required. The print function is not used after is correct. For (INT I = 0; I <sum; I ++) {If (STR = DIC [I]) {cout <STR <"is correct" <Endl; should_print = false; break ;} else if (DIC [I]. length () = Str. length () {// If the length is equal, one letter may be replaced with int flag = 0; For (Int J = 0; j <DIC [I]. length (); j ++) {If (DIC [I] [J]! = STR [J]) Flag ++;} If (flag = 1) ans [ans_sum ++] = DIC [I];} else if (DIC [I]. length ()-Str. length () = 1) {// insert a letter in STR to compare int flag = 0; For (INT str_l = 0, dic_l = 0; str_l <Str. length () & dic_l <DIC [I]. length ();) {If (STR [str_l] = DIC [I] [dic_l]) str_l ++, dic_l ++; else {dic_l ++; flag ++ ;}} if (! Flag | flag = 1) ans [ans_sum ++] = DIC [I];} else if (Str. length ()-DIC [I]. length () = 1) {// delete a letter int flag = 0; For (INT str_l = 0, dic_l = 0; str_l <Str. length () & dic_l <DIC [I]. length ();) {If (STR [str_l] = DIC [I] [dic_l]) str_l ++, dic_l ++; else {str_l ++; flag ++ ;}} if (! Flag | flag = 1) ans [ans_sum ++] = DIC [I] ;}} if (should_print) print () ;}} int main () {imput (); check (); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.