Spell Checker
Time limit:2000ms Memory limit:65536k
Total submissions:19319 accepted:7060
Description
You, as a member of a development team for a new spell checking program, is to write a module that would check the correct Ness of given words using a known dictionary of all correct words in all their forms.
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtaine D by one of the following operations:
? Deleting of one letter from the word;
? Replacing of one letter in the word with a arbitrary letter;
? Inserting of one arbitrary letter into the word.
Your task is to write the program that would find all possible replacements from the dictionary for every given word.
Input
The first part of the input file contains all words from the dictionary. Each word occupies it own line. This was finished by the character ' # ' on a separate line. All words is different. There'll is at the very 10000 words in the dictionary.
The next part of the "file contains all words" is checked. Each word occupies it own line. This was also finished by the single character ' # ' on a separate line. There'll is at the most of words that is to be checked.
All words in the input file (words from the dictionary and words to being checked) consist only of small alphabetic character s and each one contains the characters at the most.
Output
Write to the output file exactly one line for every checked word in the order of their appearance in the second part of th e input file. If the word is correct (i.e. it exists in the dictionary) write the message: ' is correct '. If The word is not correct then write this word first, then write the character ': ' (colon), and after a single space writ e all it possible replacements, separated by spaces. The replacements should is written in the order of their appearance in the dictionary (in the first part of the the input file ). If There is no replacements for this word then the line feed should immediately follow the colon.
Sample Input
I
Is
Fa=
Have
Be
My
More
Contest
Me
Too
If
Award
#
Me
Aware
M
Contest
Hav
Oo
Or
I
Fi
MRe
#
Sample Output
Me is correct
Aware:award
M:i my Me
Contest is correct
Hav:has has
Oo:too
Or
I is correct
Fi:i
Mre:more Me
Source
Northeastern Europe 1998
<span style= "color: #000099;" >/****************************************** author:grant Yuan TIME:2014/10/3 0:38 algorithm: Violence source:poj 1035*******************************************/#include <iostream> #include <cstdio> #inc lude<cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue># include<string>using namespace Std;const int max=10007;struct word{Char str[15]; int Len;}; Word s[max];int n;queue<int> ans;inline bool slove1 (word s1,word s2)//Infer whether two strings are equal {if (strcmp (S1.STR,S2.STR) ==0) r Eturn 1; return 0;} inline bool Slove2 (word s1,word s2)//Infer whether a string can be added or lowered by one character to get there is also a string {int l1=s1.len,l2=s2.len; int i,j; BOOL Ans=1; for (i=0;i<l1&&i<l2;i++) {if (s1.str[i]!=s2.str[i]) ans=0; } if (ans) return 1; for (i=0,j=0;i<l1&&j<l2;) {if (S1.str[i]==s2.str[j]) {i++;j++;} else i++; } if (i==l1&&j==l2) return 1; return 0;} inline bool Slove3 (word s1,word s2)//Whether two strings have only one character and do not want to wait {int ans=0; int L=s1.len; for (int i=0;i<l;i++) {if (s1.str[i]!=s2.str[i]) ans++; } if (ans==1) return 1; return 0;} int main () {while (!ans.empty ()) Ans.pop (); Word S1; int n=0; while (scanf ("%s", S1.str)!=eof) {if (strcmp (S1.str, ' # ') ==0) break; strcpy (S[++N].STR,S1.STR); S[n].len=strlen (S1.STR); } while (scanf ("%s", S1.str)!=eof) {while (!ans.empty ()) Ans.pop (); if (strcmp (S1.str, "#") ==0) break; BOOL Flag=1; S1.len=strlen (S1.STR); for (int i=1;i<=n;i++) {int l2=s[i].len,l1=s1.len; BOOL ans1=0; if (L1==L2) {if (slove1 (S1,s[i])) ans1=1; } if (ans1) {flag=0;printf ("%s is correct\n", s1.str); if (L1==L2) {if (Slove3 (S1,s[i])) Ans.push (i); } if (l1-l2==1) {if (Slove2 (S1,s[i])) Ans.push (i); } if (l2-l1==1) {if (Slove2 (S[I],S1)) Ans.push (i); }} if (flag) {printf ("%s:", S1.STR); while (!ans.empty ()) {printf ("%s", S[ans.front ()].str); Ans.pop ();} printf ("\ n"); }} return 0;} </span>
Copyright notice: This article Bo Master original articles, blogs, without consent, may not be reproduced.
POJ 1035 code + specific gaze