题意:给出n个字符(rule)和其代替的字符,如果字符串中有出现上述所给的字符,就要替换字符串
思路:换的时候要注意先后顺序,要第一个rule已经不能再替换了,才能进行下一个,看了别人用函数,相当快!!!strstr函数,神器。。。。。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
int n;
char s[100][100], str[100][100];
char s1[1000], s2[1000];
while (scanf("%d", &n) != EOF && n){
getchar();
for(int i = 0; i < n; i++){
gets(s[i]);
gets(str[i]);
}
gets(s1);
for(int i = 0; i < n; i++){
char *p, *q;
while (p = strstr(s1, s[i]), p != NULL){
q = p + strlen(s[i]);
strcpy(s2, str[i]);
strcat(s2, q);
strcpy(p, s2);
}
}
puts(s1);
}
return 0;
}