POJ 1035 Spell Checker

Source: Internet
Author: User
Tags alphabetic character strcmp

The character array opened up a little wa several times .... PE Once AH water problem

Spell Checker
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 22862 Accepted: 8314

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

iishashavebemymorecontestmetooifaward#meawaremcontesthavooorifimre#

Sample Output

Me is correctaware:awardm:i my mecontest was Correcthav:has haveoo:tooor:i is correctfi:imre:more me

Source

Northeastern Europe 1998[ Submit] [Go

Accode:

#include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include < Algorithm> #define MAXN 10000+5using namespace std;struct note{char word[20];} My[maxn];int N=0;char T[20];char txt[maxn][20];int TLEN[MAXN]; Note *pos;int cmp (const void *a,const void *b) {return strcmp (((note*) a)->word, ((note*) b)->word);}; int bcmp (const void *a,const void *b) {return strcmp (((char*) a), ((note*) b)->word);};    BOOL Fun1 (char *a,char *b,int l) {int cnt=0;    for (int i=0;i<l;++i) {if (a[i]==b[i]) cnt++;    } if (cnt+1==l) return true; return false;};    BOOL Fun2 (char *a,char *b) {int flag=0;            while (*a) {if (*a!=*b) {b++;            flag++;        if (flag>1) return false;            } else {a++;        b++; }} return true;};    int main () {int n=0;        while (scanf ("%s", Txt[n])!=eof&&strcmp ("#", Txt[n]) {strcpy (my[n].word,txt[n]);Tlen[n]=strlen (Txt[n]);    n++;    } qsort (My,n,sizeof (Note), CMP);        while (scanf ("%s", T)!=eof&&strcmp ("#", T)) {pos= (note*) bsearch (t,my,n,sizeof (Note), bcmp);        if (POS) printf ("%s is correct\n", Pos->word);            else{printf ("%s:", T);            int Len=strlen (t); for (int i=0;i<n;++i) {if (Len+1==tlen[i]) {if (fun2 (T,txt[i])) print                F ("%s", Txt[i]);                 } else if (Len==tlen[i]) {if (fun1 (T,txt[i],len)) printf ("%s", Txt[i]); } else if (Len-1==tlen[i]) {if (fun2 (txt[i],t)) printf (                "%s", Txt[i]);        }} putchar (' \ n '); }} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1035 Spell Checker

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.