4
ban
bab
baba
be
ana
any
ba b
hind the g
banana boat
Sample Output
behind the goat
用pos寻找原串中M1的位置,存在即不为0.删除后插入N1,直到为0进入下一条规则。
var
x:string;
a,b:array[1..1000] ofstring;
i,l,n:longint;
begin
readln(n);
for i:=1to n dobegin
readln(a[i]);
readln(b[i]);
end;
readln(x);
for i:=1to n dobegin
l:=pos(a[i],x);
while l<>0dobegin
delete(x,l,length(a[i]));
insert(b[i],x,l);
l:=pos(a[i],x);
end;
end;
writeln(x);
end.