#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_RULE 11
#define MAX_CHAR 3001
char tmp[MAX_CHAR], text[MAX_CHAR];
string find_str[MAX_RULE], replace_str[MAX_RULE];
void replace_str_find_str(int idx, char *p)
{
// printf("***********************\n");
// printf("%s\n", text);
// printf("%s -> %s\n", find_str[idx].c_str(), replace_str[idx].c_str());
int pos(0);
for(char *i = text; i != p; i ++) {
tmp[pos ++] = *i;
}
for(int i = 0; i < find_str[idx].length(); i ++, p ++) {
// tmp[pos ++] = replace_str[idx][i];
}
for(int i = 0; i < replace_str[idx].length(); i ++) {
tmp[pos ++] = replace_str[idx][i];
}
for( ; '\0' != *p; p ++) {
tmp[pos ++] = *p;
}
tmp[pos] = '\0'; strcpy(text, tmp); //printf("%s\n", text);
//printf("***********************\n");
}
void auto_edit(const int &n)
{
char *p;
for(int i = 0; i < n; i ++) {
while( p = strstr(text, find_str[i].c_str()) ) {
replace_str_find_str(i, p);
}
}
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n;
while( scanf("%d", &n) && n) { getchar();
for(int i = 0; i < n; i ++) {
gets(tmp); find_str[i].clear(); find_str[i] += tmp;
gets(tmp); replace_str[i].clear(); replace_str[i] += tmp;
}
gets(text); auto_edit(n); printf("%s\n", text);
}
return 0;
}
uva_10115_Automatic Editing
最新推荐文章于 2021-07-28 20:05:23 发布