-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10115.c
60 lines (57 loc) · 997 Bytes
/
10115.c
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
#include<stdio.h>
#include<string.h>
char s[10000][500],sc[10000][500],find[100000];
void replace(char *find,char *s,char *sc)
{
int i,j,flag=0;
int len1,len2,len3;
len1=strlen(find);
len2=strlen(s);
len3=strlen(sc);
for (i=0;i<len1;i++)
if (s[0]==find[i])
{
flag=0;
for (j=1;j<len2;j++)
if (s[j]==find[i+j]);
else {flag=1;break;}
if (!flag)
{
if (len2<len3)
for (j=len1;j>=i+len2-1;j--)
find[j+len3-len2]=find[j];
else if (len2>len3)
if (len3!=0)
for (j=i+len2-1;j<=len1;j++)
find[j-(len2-len3)]=find[j];
else
for (j=i;j<=len1-len2;j++)
find[j]=find[j+len2];
for (j=0;j<len3;j++)
find[i+j]=sc[j];
len1=strlen(find);
i=0;
}
}
}
main()
{
int i,j,k,l,m,n;
while (scanf("%d",&n),n)
{
getchar();
for (i=0;i<n;i++)
{
gets(s[i]);
gets(sc[i]);
}
gets(find);
for (i=0;i<n;i++)
replace(find,s[i],sc[i]);
puts(find);
memset(s,0,sizeof(s));
memset(sc,0,sizeof(sc));
memset(find,0,sizeof(find));
}
return 0;
}