POJ 1035 Spell checker

Source: Internet
Author: User

Spell checkerTime Limit: 2000 MS Memory Limit: 65536 KTotal Submissions: 15145 Accepted: 5504 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness 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 Dictionary) that can be obtained by one of the following operations :? Deleting of one letter from the word ;? Replacing of one letter in the word with an arbitrary letter ;? Inserting of one arbitrary letter into the word. your task is to write the program that will 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 its own line. this part is finished by the single character '#' on a separate line. all words are different. there will be at most 10000. Words in the dictionary. the next part of the file contains all words that are to be checked. each word occupies its own line. this part is also finished by the single character '#' on a separate line. there will be at most 50 words that are to be checked. all words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contai Ns 15 characters at 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 the 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 write all its possibl E replacements, separated by spaces. the replacements shocould be written in the order of their appearance in the dictionary (in the first part of the input file ). if there are no replacements for this word then the line feed shoshould immediately follow the colon. sample Input iishashavebemymorecontestmetooifaward # meawaremcontesthavooorifimre # Sample Output me is correctaware: awardm: I my mecontest is Correcthav: has haveoo: tooor: I is correctfi: imre: more meSource Northeastern Europe 1998 first clear the idea and use the most common method; then go to bed [cpp] # include <iostream> # include <string> using namespace std; string s1 [20000]; string s2; int main () {int I, j, n, m, s, t, x, k; int l1, l2; I = 0; while (1) {getline (cin, s2); if (s2 = "#") {break;} s1 [I] = s2; I ++;} n = I; while (1) {getline (cin, s2 ); if (s2 = "#") {break;} for (I = 0; I <= n-1; I + +) {If (s1 [I] = s2) {break ;}} if (I! = N) {cout <s2 <"is correct" <endl;} else {cout <s2 <":"; l2 = s2.size (); for (I = 0; I <= n-1; I ++) {l1 = s1 [I]. size (); k = 0; if (l1 = l2) {for (j = 0; j <= l1-1; j ++) {if (s1 [I] [j]! = S2 [j] & k = 0) {k = 1;} else if (s1 [I] [j]! = S2 [j]) {break; }}if (j = l1) {cout <"" <s1 [I] ;}} else if (L1-L2 = 1) {for (j = 0, x = 0; j <= l1-1; j ++) {if (s1 [I] [j]! = S2 [x] & k = 0) {k = 1;} else if (s1 [I] [j]! = S2 [x]) {break;} else if (s1 [I] [j] = s2 [x]) {x ++ ;}} if (j = l1) {cout <"" <s1 [I] ;}} else if (l2-l1 = 1) {for (j = 0, x = 0; j <= l2-1; j ++) {if (s1 [I] [x]! = S2 [j] & k = 0) {k = 1;} else if (s1 [I] [x]! = S2 [j]) {break;} else if (s1 [I] [x] = s2 [j]) {x ++ ;}} if (j = l2) {cout <"" <s1 [I] ;}}cout <endl ;}} return 0 ;}

Related Article

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.