/*
coder: Shawn_Xue
date: 2015.3.9
result: AC
description: UVA - 10115 Automatic Editing
*/
#include <stdio.h>
#include <string.h>
int main()
{
int n;
char find[80][150], re[80][150], str[500] = {'\0'}, tmp[500] = {'\0'};//str,tmp必须足够大,否则RE
while(scanf("%d", &n) == 1 && n)
{
getchar(); // 消去回车
for(int i = 0; i < n; i ++)
{
gets(find[i]);
gets(re[i]);
}
gets(str);
for(int i = 0; i < n; i ++)
{
if(strstr(str, find[i]) != NULL) // 判断是否存在find[i]
{
char *p = strstr(str, find[i]);
int len = strlen(find[i]); // 计算find后字符长度
strcpy(tmp, p+len); // 保存find后字符入tmp
/* 点睛之笔 */
*p = '\0'; // 替换p指向的字符为'\0',截断find后字符
strcat(str, re[i]); // re中的字符连接在str前半部分之后
strcat(str, tmp); // 将tmp中保存的find后字符连接在str后
i--; // 再次循环,检查本次find[i]
}
}
puts(str);
}
return 0;
}