PKU 1035 spell checker

Source: Internet
Author: User

Well, I really want to see that the trie tree is used for classification, but I have no idea about it, and I am using brute force.

If the same word cannot be found, there are only three similar cases.

CodeGood understanding

# Include <iostream> using namespace STD; # define maxn 10001 char STR [maxn] [20]; bool Replace (char * a, char * B) {int L1 = strlen (a); int L2 = strlen (B); If (L1 = l2) // modify a character {int I = 0; while (I <L1 & A [I] = B [I]) // locate the position of the first different character I ++; while (++ I <L1) // check whether the subsequent characters are the same {if (a [I]! = B [I]) return false ;}} else if (L1 = l2 + 1) // Add a character {int I = 0; while (I <L2 & A [I] = B [I]) I ++; while (++ I <L1) // A skips a character and B compares {if (a [I]! = B [I-1]) return false;} else if (l1 + 1 = l2) // delete a character, which is similar to {int I = 0; while (I <L1 & A [I] = B [I]) I ++; while (I ++ <l2) {if (a [I-1]! = B [I]) return false ;}} else return false; return true ;}int main () {int I = 0; bool flag; char C [20]; while (scanf ("% s", STR [I ++])! = EOF & strcmp (STR [I-1], "#")! = 0); I --; while (scanf ("% s", c )! = EOF & strcmp (C ,"#")! = 0) {flag = false; For (Int J = 0; j <I; j ++) if (strcmp (STR [J], c) = 0) {flag = true; break;} If (FLAG) printf ("% s is correct \ n", c); else {printf ("% s:", C ); for (Int J = 0; j <I; j ++) {If (replace (STR [J], c) printf ("% s ", STR [J]);} printf ("\ n") ;}} 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.