Spell Checker (POJ 1035)

Source: Internet
Author: User

Test instructions

This question is a string problem, first of all to give a dictionary, which stores a number of words. Then, give a word, if the dictionary exists, then the output correct, if not in the dictionary, then it is necessary to determine whether the word is wrong, there are 3 errors, the first is a letter of the word type is wrong, and the dictionary word is only one letter different, the second is a word more than a letter , and if the letter is removed, it is consistent with a word in the dictionary. The third is a word less than a letter, if you add the letter, and the dictionary is consistent with a word. The goal is to output the words in the dictionary corresponding to these kinds of errors. Brute force solution Timeout!!!
#include <cstdio>#include<iostream>#include<cstring>#defineM 10010#defineN 15using namespacestd;CharCh[m][n],s[n];intA[m];intSearchChar*a,Char*b) {    intLena=strlen (a); intlenb=strlen (b); if(lena==LenB) {        intflag=0;  for(intI=0; i<lena;i++)          if(a[i]!=B[i])if(!flag) flag=1; Else return 0; if(flag==1)return 1; }    if(lena==lenb+1)    {        intPa=0, pb=0, flag=0;  while(1)        {            if(PA&GT;=LENA&AMP;&AMP;PB&GT;=LENB) Break; if(a[pa]==B[PB]) {PA++; PB++; }            Else              if(!flag) {Flag=1; PA++; }              Else return 0; }        if(flag==1)return 1; }    if(lena==lenb-1)    {        intPa=0. P =0, flag=0;  while(1)        {            if(PA&GT;=LENA&AMP;&AMP;PB&GT;=LENB) Break; if(a[pa]==B[PB]) {PA++; PB++; }            Else              if(!flag) {Flag=1; PB++; }              Else return 0; }        if(flag==1)return 1; }    return 0;}intMain () {intn=0;  while(1) {scanf ("%s", ch[++n]); if(ch[n][0]=='#') {n--;  Break; }    }     while(1)    {        intflag=0, cnt=0; scanf ("%s", s); if(s[0]=='#') Break; printf ("%s", s);  for(intI=1; i<=n;i++)        {            if(strcmp (s,ch[i]) = =0) {printf ("is correct\n"); Flag=1;  Break; }            Else if(Search (S,ch[i])) a[++cnt]=i; }        if(!flag) {printf (":");  for(intI=1; i<=cnt;i++) printf ("%s", Ch[a[i]]); printf ("\ n"); }    }    return 0;}
View Code

Spell Checker (POJ 1035)

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.