-
Notifications
You must be signed in to change notification settings - Fork 2
/
10115.cpp
95 lines (70 loc) · 1.41 KB
/
10115.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char text[300];
char word[15][85];
int s,e;
int rep(char word1[],char word2[]) {
int k,d,a,i,j;
k = strlen(text);
if( strlen(word1)<strlen(word2) ){
d = strlen(word2) - strlen(word1);
a = k + d - 1;
for(i = a; i >= e+d; i --)
text[i] = text[i-d];
for(i = 0; word2[i]; i ++)
text[s+i] = word2[i];
text[a+1] = NULL;
}
else if(strlen(word1) > strlen(word2)) {
d= strlen(word1) - strlen(word2);
for(i = 0; word2[i]; i ++)
text[s+i] = word2[i];
a = s + strlen(word2);
for(j = a; text[j]; j ++)
text[j] = text[j+d];
text[j] = NULL;
}
else {
for(i = 0; word2[i]; i++)
text[s+i] = word2[i];
}
return 0;
}
int p_match(char key[]) {
int i,j,max,c;
max = strlen(text) - strlen(key);
for(i = 0;i<=max; i++) {
c = 1;
for(j = 0; key[j]; j++) {
if(text[i+j] != key[j]) {
c = 0;
break;
}
}
if(c) {
s = i;
e = i + strlen(key) - 1;
return 1;
}
}
return 0;
}
int main() {
int i,j,k;
char n[5];
while(gets(n) && atoi(n)) {
k = atoi(n);
for(i = 0; i<k*2; i++)
gets(word[i]);
gets(text);
for(i = 0; i<k*2-1; i +=2) {
while(p_match(word[i]))
rep(word[i],word[i+1]);
}
for(i = 0; text[i]; i++)
printf("%c", text[i]);
printf("\n");
}
return 0;
}