[Cpp]
/** The meaning of this question is to convert the previous string into the next string, the current string
* If no result is found, compare the Next string until all strings are replaced.
*/
# Include <cstdio>
# Include <iostream>
# Include <cstring>
Using namespace std;
# Deprecision MAX 256
// Replace
Void replace (char * a, char * B, int pos ){
For (int I = 0; I <strlen (a); I ++ ){
B [pos ++] = a [I];
}
}
// Search for substrings
Int findSon (char * s1, char * s2, int & start, int & end ){
Int j, i1;
For (int I = 0; I <strlen (s2); I ++ ){
I1 = I;
For (j = 0; j <strlen (s1); j ++ ){
If (s1 [j]! = S2 [i1 ++]) break;
}
If (j = strlen (s1 )){
Start = I; end = I + J-1; return 1;
}
}
Return 0;
}
Int main (int argc, char const * argv []) {
Int cas, start, end, len, flag;
Char data [MAX];
Char word [MAX] [MAX];
While (cin> cas, cas! = 0 ){
Getchar ();
For (int I = 0; I <2 * cas; I + = 2 ){
Gets (word [I]);
Gets (word [I + 1]);
}
Gets (data );
For (int I = 0; I <2 * cas; I + = 2 ){
Flag = 1;
While (flag ){
Flag = findSon (word [I], data, start, end );
Len = strlen (word [I])-strlen (word [I + 1]);
// Whether there are replaceable strings in the flag ID. The following code replaces the strings without using library functions.
If (flag ){
If (len <0 ){
Len =-len;
For (int I = strlen (data); I> end; I --){
Data [I + len] = data [I];
}
} Else if (len> 0 ){
For (int I = end-len + 1; I <strlen (data); I ++ ){
Data [I] = data [I + len];
}
}
Replace (word [I + 1], data, start );
}
}
}
Puts (data );
}
Return 0;
}