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>=LENA&&PB>=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>=LENA&&PB>=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)