字符串函数的应用。
# include <cstdio> # include <cstring> # define RULESN 10 + 5 # define MAXLEN 80 + 5 int n; char src[RULESN][MAXLEN]; char des[RULESN][MAXLEN]; char text[4 * MAXLEN]; void replace(char *t, char *s, char *d) { int len = strlen(s); char *p, tmp[4 * MAXLEN]; while (p = strstr(t, s)) { strcpy(tmp, p), t[p-t] = 0; strcat(t, d), strcat(t, tmp+len); } } int main() { while (scanf("%d", &n), n) { getchar(); for (int i = 0; i < n; ++i) gets(src[i]), gets(des[i]); gets(text); for (int i = 0; i < n; ++i) replace(text, src[i], des[i]); puts(text); } return 0; }
/**/