hihocoder1440 : keywords filter

Description

You are given a string S which consists of only lower case letters and N keyword W1, W2, … WN which also consists of only lower case letters. For each appearance of a keyword in S you need to change the letters matching the keyword into ‘*‘.

Assume

= "abcxyzabcd"``` and keywords are {"abc", "cd"}, the filtered S' will be ```"***xyz****"```.
1
2
3
4
5
6
7
8
9
10
11
12
## Input
The first line contains an integer N. (1 <= N <= 1000)
The following N lines each contains a keyword. The total length of the keywords is no more than 100000.
The last line contains the string S. The length of S is no more than 100000.
## Output
The filtered string.
## Sample Input

2
abc
cd
abcxyzabcd

1
##Sample Output

xyz*

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
# 2. Analysis
# 3. Solution(s)
```python
N = int(raw_input())
keywords = list()
for i in xrange(N):
keywords.append(raw_input())
S = raw_input()
flag = [0] * len(S)
for word in keywords:
tmp = 0
while S.count(word, tmp) != 0:
index = S.find(word, tmp)
for i in xrange(len(word)):
flag[index + i] = 1
tmp = index + 1
res = ""
for i in xrange(len(flag)):
if flag[i]:
res += S[i]
else:
res += "*"
print res