Poj 1035 spell checker string

Source: Internet
Author: User

# Include <iostream> using namespace STD; string DIC [10010]; string CHE [60]; int DC, CC, flag; void setfile () // enter {Dc = Cc = 0; do {DC ++; CIN> DIC [DC];} while (DC <= 10000 & DIC [DC] [0]! = '#'); Do {CC ++; CIN> CHE [CC] ;}while (CC <= 50 & CHE [CC] [0]! = '#');} Void modify (int n) {string res [500], tempstr; int I, j, T, CNT = 0; for (I = 1; I <DC; I ++) {T = CHE [N]. size ()-DIC [I]. size (); If (t = 1) // when the word to be queried is 1 longer than the word in the dictionary, insert a letter into the dictionary to compare it. {For (j = 0; j <CHE [N]. Size (); j ++) {If (CHE [N] [J]! = DIC [I] [J]) {tempstr = DIC [I]; tempstr. insert (J, 1, CHE [N] [J]); If (tempstr = CHE [N]) RES [++ CNT] = DIC [I]; elsebreak ;}}}if (t =-1) // when the word to be queried is 1 shorter than the word in the dictionary, insert a letter into the word to be queried to compare with the word in the dictionary. {For (j = 0; j <DIC [I]. Size (); j ++) {If (CHE [N] [J]! = DIC [I] [J]) {tempstr = CHE [N]; tempstr. insert (J, 1, DIC [I] [J]); If (tempstr = DIC [I]) RES [++ CNT] = tempstr; elsebreak ;}}} if (t = 0) // when the word to be queried is the same as the word in the dictionary, replace a letter for comparison. {For (j = 0; j <CHE [N]. Size (); j ++) {If (CHE [N] [J]! = DIC [I] [J]) {tempstr = CHE [N]; tempstr. replace (J, 1, DIC [I], J, 1); If (tempstr = DIC [I]) RES [++ CNT] = tempstr; elsebreak ;}}}for (I = 1; I <= CNT; I ++) cout <''<res [I]; cout <Endl ;} void check () {int I, j; flag = false; for (I = 1; I <cc; I ++) {for (j = 1; j <DC; j ++) {If (CHE [I] = DIC [J]) {flag = true; break ;}} if (FLAG) cout <CHE [I] <''<" is correct "<Endl; else {cout <CHE [I] <":"; modify (I);} flag = false;} int main () {setfile (); check (); Return 0 ;}

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.