POJ 1035 Spell Checker

Source: Internet
Author: User
Tags alphabetic character

Topic Link http://poj.org/problem?id=1035

Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 24142 Accepted: 8794

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
1#include <stdio.h>2#include <iostream>3#include <math.h>4#include <algorithm>5#include <string.h>6 using namespacestd;7 intjilu[10005];8 structnode9 {Ten     Chars[ -]; One     intLen; A}word[10005]; - intCheckChar*a,intLena,node b)//Replaceable to 1, non-replaceable to 0, equal to 2 - { the     inti,j; -     if(Lena==b.len)//equal or replaceable -     { -         intbuxiangdeng=0; +          for(i=0; i<lena;i++) -         { +             if(A[i]!=b.s[i]) buxiangdeng++; A             if(buxiangdeng>=2) Break; at         } -         if(buxiangdeng==0)return 2; -         Else if(buxiangdeng==1)return 1; -     } -     Else if(lena-1==b.len)//can be deleted -     { in         intxiangdeng=0; -          for(i=0, j=0; i<lena&&j<b.len;i++,j++) to         { +             if(a[i]!=B.s[j]) -             { thej--; *             } $             Elsexiangdeng++;Panax Notoginseng         } -         if(Xiangdeng==b.len)return 1; the     } +     Else if(lena+1==b.len)//can be inserted A     { the         intxiangdeng=0; +          for(i=0, j=0; i<lena&&j<b.len;i++,j++) -         { $             if(a[i]!=B.s[j]) $             { -i--; -             } the             Elsexiangdeng++; -         }Wuyi         if(Xiangdeng==lena)return 1; the     } -     return 0; Wu } - BOOLFlag//whether there is About intMain () $ { -     intI=0; -      for(;; i++) -     { ACin>>Word[i].s; +word[i].len=strlen (WORD[I].S); the         if(word[i].s[0]=='#') -              Break; $     } the     intn=i; the     //read in dictionary the     Chara[ -]; the      while(cin>>a) -     { in         if(a[0]=='#') Break; the         intj=0;//the serial number in the record theflag=false; About         intLena=strlen (a); the          for(i=0; i<n;i++) the         { the             intt=check (a,lena,word[i]); +             if(t==2) -             { theflag=true;Bayi                  Break; the             } the             Else if(t==1) -             { -jilu[j]=i; theJ + +; the             } the         } the         if(flag) cout<<a<<"is correct"<<Endl; -         Else the         { thecout<<a<<":"; the              for(i=0; i<j;i++)94             { thecout<<" "<<Word[jilu[i]].s; the             } thecout<<Endl;98         } About     } -     return 0;101}

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.