Address: Spell checker
Question:
Here is a string dictionary for you to judge the correctness of the input string based on the string in the dictionary. If the string is incorrect, you can use the following operations to output the possibility of a string: 1. You can replace one character, 2. You can delete one character, and 3. You can add one character. If the above operations are met, it indicates the possibility of a string and then outputs it.
Solution:
You can judge the four situations. If the output is correct, if the first, second, and third situations occur, first store the string in a character array s [N] [N]. If all the judgments are complete, there is no correctness, and the possible strings are output.
Code:
1 # include <algorithm> 2 # include <iostream> 3 # include <sstream> 4 # include <cstdlib> 5 # include <cstring> 6 # include <cstdio> 7 # include <string> 8 # include <bitset> 9 # include <vector> 10 # include <queue> 11 # include <stack> 12 # include <cmath> 13 # include <list> 14/ /# include <map> 15 # include <set> 16 using namespace STD; 17 /************************************** */18 # define ll long 19 # Define int64 _ int64 20 /******************************** * *****/21 const int INF = 0x7f7f7f7f; 22 const double EPS = 1e-8; 23 const double PIE = ACOs (-1.0); 24 const int d1x [] = }; 25 const int d1y [] = {0,-}; 26 const int d2x [] = {0,-, 1}; 27 const int d2y [] =, -}; 28 const int FX [] = {-1,-1,-,}; 29 const int FY [] = {-, 1, -,-, 1}; 30 /**************************** * *********/31 void openfile () 32 {33 freopen ("data. in "," rb ", stdin); 34 freopen (" data. out "," WB ", stdout); 35} 36/************************* gorgeous split line, the template section is *****************/37 char S1 [10001] [16], s [10001] [16]; 38 char S2 [51] [16]; 39 int main () 40 {41 memset (S1, 0, sizeof (S1); 42 memset (S2, 0, sizeof (S2); 43 memset (S, 0, sizeof (s); 44 int M, N; 45 int I, J, K; 46 for (I = 0; I ++) 47 {48 scanf ("% s", S1 [I]); 49 m = I; 50 if (S1 [I] [0] = '#') 51 break; 52 53} 54 for (I = 0; I ++) 55 {56 scanf ("% s", S2 [I]); 57 n = I; 58 If (s2 [I] [0] = '#') 59 break; 60} 61 for (I = 0; I <n; I ++) 62 {63 int len1 = strlen (s2 [I]); 64 65 int flag = 0; 66 int D = 0, H; 67 for (j = 0; j <m; j ++) 68 {69 int CNT = 0; 70 int len2 = strlen (S1 [J]); 71 int Ce = len1-len2; 72 If (Ce> 1 | ce <-1) 73 continue; 74 for (k = 0, H = 0; k <len1;) 75 {76 if (s2 [I] [k]! = S1 [J] [H] & len1> len2) 77 {78 K ++; 79 continue; 80} 81 If (s2 [I] [k]! = S1 [J] [H] & len1 <len2) 82 {83 H ++; 84 If (h> = len2) 85 break; 86 continue; 87} 88 If (s2 [I] [k] = S1 [J] [H]) 89 {90 CNT ++; 91} 92 K ++; 93 h ++; 94} 95 If (CNT = len1 & len1 = len2) 96 {97 flag = 1; 98 break; 99} 100 else if (CNT = len1 & len1 <len2) 101 {102 flag = 2; 103 strcpy (s [d], S1 [J]); 104 D ++; 105} 106 else if (CNT = len2 & len1> len2) 107 {108 flag = 3; 109 strcpy (s [d], s1 [J]); 110 d ++; 111} 112 else if (CNT = len2-1 & len1 = len2) 113 {114 flag = 4; 115 strcpy (s [d], S1 [J]); 116 d ++; 117} 118} 119 If (flag = 1) 120 printf ("% s is correct \ n", S2 [I]); 121 else122 {123 printf ("% s:", S2 [I]); 124 for (j = 0; j <D; j ++) 125 printf ("% s", s [J]); 126 printf ("\ n "); 127} 128 129} 130 return 0; 131}
View code