POJ 1035.Spell Checker

Source: Internet
Author: User
Tags alphabetic character

Spell Checker Time limit:2000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U Submit Status Practice POJ 1035

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

Give some legal words and some words to be tested, if the word to be tested is valid, then output "xx is correct".

Otherwise, the output deletes, modifies, adds a character after the valid word

Output in order of input

There is a trie tree, writing has been WA, TLE

The use of violent solutions

AC Code: GITHUB

1 /*2 By:ohyee3 Github:ohyee4 Homepage:http://www.oyohyee.com5 Email:[email protected]6 Blog:http://www.cnblogs.com/ohyee/7 8 かしこいかわいい? 9 エリーチカ! Ten to write out the хорошо code OH ~ One */ A  -#include <cstdio> -#include <algorithm> the#include <cstring> -#include <cmath> -#include <string> -#include <iostream> +#include <vector> -#include <list> +#include <queue> A#include <stack> at#include <map> - using namespacestd; -  - //DEBUG MODE - #defineDebug 0 -  in //Loops - #defineREP (n) for (int o=0;o<n;o++) to  + intOK; - intLdict,lstr; the stringtemp; *vector<string>dict; $ Panax Notoginseng  - voidReplacestringdict) { the     intCount =0; +      for(size_t i =0; I < dict.length (); i++) { A         if(Temp[i]! = Dict[i]) count++; the         if(Count >1)return; +     } -OK =1; $cout <<" "+dict; $ } -  - voidInsertstringdict) { the     stringtmp; -      for(size_t i =0; I < temp.length (); i++) {Wuyi         if(Temp[i]! =Dict[i]) { theTMP =dict; -Tmp.insert (I,1, Temp[i]); Wu             if(TMP = =temp) { -OK =1; Aboutcout <<" "+dict; $             } -             return; -         } -     } A } +  the voidDelstringdict) { -     stringtmp; $      for(size_t i =0; I < dict.length (); i++) { the         if(Temp[i]! =Dict[i]) { theTMP =dict; theTmp.erase (I,1); the             if(TMP = =temp) { -OK =1; incout <<" "+dict; the             } the             return; About         } the     } the } the  + BOOLDo () { -      while(1) { the         if(! (Cin >>temp))Bayi             return false; the         if(temp = ="#") Break; the Dict.push_back (temp); -     } -  the      while(1) { theCIN >>temp; the         if(temp = ="#") Break; the  -OK =-1; theLstr =temp.length (); the  the          for(size_t i =0; I < dict.size (); i++) {94             if(Dict[i] = =temp) { thecout << temp +"is correct"; theOK =0; the                  Break;98             } About         } - 101 102         if(OK <0) {103cout << temp +':';104              for(size_t i =0; I < dict.size (); i++) { theLdict =dict[i].length ();106                 if(Lstr = =ldict) {107 replace (dict[i]);108}Else if(Lstr = = Ldict +1) {109 Insert (Dict[i]); the}Else if(Lstr = = Ldict-1) {111 del (dict[i]); the                 }113             } the         } the  thecout <<Endl;117     }118 119     return true; - }121 122 intMain () {123      while(Do ());124     return 0; the}

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.