/* Question 1) Introduction input: Regular Expression string to be matched string, if the input "######" program ends, output: If the matching is successful, the entire string is output, if the match fails, output the lost and wait for the next user input. ^ Indicates the start of the string. represents any character $ represents the end of the string 2) reference input, output ^. $ abc response regular express and target string (separate by space), inputlost response result, outputab. $ ababc release regular express and target string (separate by space), inputababc match successfully, print the target string, output ###### complete input ##### end the entire program */# include <stdio. h> # include <string. h> # define X 20int main () {int I, j, x1, x2, u, flag, ret, w; char str1 [X], str2 [X]; for (u = 0; u ++) {scanf ("% s", str1); scanf ("% s", str2); x1 = strlen (str1 ); x2 = strlen (str2); flag = 0; if (x1 = 3 & x2 = 3) {for (I = 0; I <3; I ++) {if (str1 [I]! = '#' | Str2 [I]! = '#') Flag ++;} if (flag = 0) return 0;} if (str1 [0] = '^ ') /* 1 & 2 */{if (str1 [x1-1] = '$') {if (x1 = x2 + 2) for (I = 1; I <x1-1; I ++) {if (str1 [I]! = '.') {If (str1 [I]! = Str2 [I-1]) {printf ("lost \ n"); break;} else {if (I = x1-2) {puts (str2); break ;}}} else continue;} else printf ("lost \ n");} else/* 2 */{if (x2 <x1-1) printf ("lost \ n "); else for (I = 1; I <x1; I ++) {if (str1 [I]! = '.') {If (str1 [I]! = Str2 [I-1]) {printf ("lost \ n"); break;} else if (I = x1-1) {puts (str2); break ;}} else continue;} else/* 3 & 4 */{if (str1 [x1-1] = '$')/* 3 */{if (x2 <x1-1) printf ("lost \ n"); else {for (I = x1-2; I> = 0; I --) {if (str1 [I]! = '.') {If (str1 [I]! = Str2 [x2-x1 + I + 1]) {printf ("lost \ n"); break;} else {if (I = 0) {puts (str2 ); break ;}}}} else/* 4 */{ret = 0; if (x1> x2) printf ("lost \ n "); else {for (w = 0; w <x1; w ++) if (str1 [w]! = 0) break; for (j = w; j <x2; j ++) {if (str1 [w] = str2 [j]) for (I = 1; I <x1-w; I ++) {if (str1 [I + w]! = '.') {If (str1 [I + w]! = Str2 [I + j]) break; else {if (I + w = x1-1) {ret = 1; puts (str2 );}}}} if (ret = 1) break;} if (ret! = 1) printf ("lost \ n") ;}}} return 0 ;}