The general meaning is to replace the strings in the first column of the list with the strings in the second column until all the strings in the entire sentence are replaced, then replace the Next string. The question itself is not difficult. I believe that if you take it seriously, you can easily AC it ~
(If strstr () and sprintf functions are usedCodeA lot of conciseness and efficiency will be improved. Of course, if STL string is used, it will be very fast .)
The Code is as follows:
# include
# include
# include
int main () {# ifdef sta freopen ("sample. text "," r ", stdin); # endif int K, I; char * ffct; // define a character pointer char sum [20 + 1] [80 + 1], A [260], B [260], C [260]; while (scanf ("% d", & K) {getchar (); If (k = 0) break; memset (sum, 0, sizeof (SUM); memset (A, 0, sizeof (a); memset (B, 0, sizeof (B )); for (I = 0; I <= 2 * K-1; I ++) gets (sum [I]); gets (a); for (I = 0; I <= 2 * K-1; I = I + 2) while (1) {ffct = strstr (A, sum [I]); // find the place where the string to be replaced appears if (ffct = NULL) break; sprintf (C, "% s", ffct + strlen (sum [I]); // Save the strings behind the replacement part to sprintf (ffct, "% s", sum [I + 1]) in the C array. // Replace the part to be replaced (the string after replacement is overwritten) sprintf (ffct + strlen (sum [I + 1]), "% s ", c); // Add the temporary string} printf ("% s \ n", a);} return 0 ;}