POJ 1035-spell Checker (String)

Source: Internet
Author: User

Title Address: POJ 1035
Test instructions: Enter a dictionary and enter several words. If a word can be found in the dictionary, then output corret; If a word can be found in the dictionary by changing or deleting or adding a character, the output is output in the dictionary order according to the dictionary entered; If a word cannot be found in the dictionary, whether or not it is manipulated or not, the output is empty.
Ideas: About the exact match on the direct output is good, the key to solving the problem is not exactly matching the situation: when we compare the difference between the two words, there are three cases: Len1=strlen (str) Len2=strlen (Mp[n]
If Len1==len2 is likely to have a character different; compare characters by character, count the characters
If Len1+1==len2 is less one character, character by case comparison, if there are different characters, then the mp[n] character subscript downward move one bit, str unchanged, different characters plus 1
If Len1-1==len2 is more than one character, by character comparison, if there are different characters, then the STR character subscript moves down one bit, mp[n] unchanged, the number of different characters plus 1

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef__int64 LL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;Const intmaxn=10010;Charmp[maxn][ -];Charstr[ -];intCheckintN) {intI,j;intCntintlen1=strlen(str);intLen2=strlen(Mp[n]);if(len1-len2==1) {cnt=0; i=j=0; for(; i<len1;) {if(Str[i]!=mp[n][j])                {cnt++;            i++; }Else{i++;            j + +; }        }if(cnt==1)return 1;return 0; }Else if(LEN1==LEN2) {cnt=0; i=j=0; for(; i<len1;) {if(Str[i]!=mp[n][j]) cnt++;        i++,j++; }if(cnt==1)return 1;return 0; }Else if(len1-len2==-1) {cnt=0; i=j=0; for(; j<len2;) {if(Str[i]!=mp[n][j])                {cnt++;            j + +; }Else{i++;            j + +; }        }if(cnt==1)return 1;return 0; }return 0;}intMain () {intn=0I while(~scanf('%s ', Mp[n])) {if(mp[n][0]==' # ') Break;    n++; } while(~scanf('%s ', str)) {if(str[0]==' # ') Break; for(i=0; i<n; i++) {if(strcmp(Str,mp[i]) = =0) {printf("%s is correct\n", str); Break; }        }if(i==n) {printf("%s:", str); for(i=0; i<n; i++)if(check (i))printf('%s ', Mp[i]);puts(""); }    }return 0;}

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

POJ 1035-spell Checker (String)

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.