Poj 1035 spell checker

Source: Internet
Author: User
// There are many situations to consider. You need to simulate it step by step. Be careful which string is the length of the value! # Include <iostream> # include <string> # include <vector> # include <algorithm> using namespace STD; vector <string> V; void is_replace (string str1, string str2) {int I, Len, c = 0; Len = str1.length (); for (I = 0; I <Len; I ++) {If (str1 [I]! = Str2 [I]) C ++;} If (C = 1) {cout <"<str2; return ;}} void is_insert (string str1, string str2) {int I, Len; Len = str1.length (); for (I = 0; I <Len; I ++) {If (str1 [I]! = Str2 [I]) {string TMP; TMP = str2; TMP. insert (I, 1, str1 [I]); If (TMP = str1) {cout <"" <str2; break ;}} return ;} void is_delete (string str1, string str2) {int I, Len; Len = str2.length (); for (I = 0; I <Len; I ++) {If (str1 [I]! = Str2 [I]) {string TMP; TMP = str2; TMP. erase (I, 1); If (TMP = str1) {cout <"" <str2; break ;}}return ;}int main () {int I, s, len1, len2; bool flag, flag1; string STR; // dictionary word input while (CIN> Str) {If (STR = "#") break; v. push_back (STR);} s = v. size (); While (CIN> Str) {If (STR = "#") break; len1 = Str. length (); flag = flag1 = false; for (I = 0; I <s; I ++) {If (STR = V [I]) {cout <<STR <"is correct"; flag1 = true; break ;}} if (! Flag1) {If (! Flag) {cout <STR <":"; flag = true ;}for (I = 0; I <s; I ++) {len2 = V [I]. length (); If (len1 = len2) {is_replace (STR, V [I]);} else if (len1 = len2 + 1) {is_insert (STR, V [I]);} else if (len1 = len2-1) {is_delete (STR, V [I]) ;}} cout <Endl ;} system ("pause ");}

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.