-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8960 - Naive String Matching.py
53 lines (40 loc) · 1.33 KB
/
8960 - Naive String Matching.py
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
"""
/**********************************************************************************************************
NAME: CANDIDA RUTH NORONHA
CLASS: SE COMPS B
ROLL NO. : 8960
BATCH: C
TITLE: NAIVE STRING MATCHING
SUBMISSION DATE : 9th MAY, 2021
**********************************************************************************************************/
"""
def search(pat, txt):
M = len(pat)
N = len(txt)
# A loop to slide pat[] one by one */
for i in range(N - M + 1):
j = 0
# For current index i, check
# for pattern match */
while(j < M):
if (txt[i + j] != pat[j]):
break
j += 1
if (j == M):
print(" Pattern found at index : ", i)
# Driver Code
if __name__ == '__main__':
txt = str(input(" Enter the text : "))
pat = str(input(" Enter the pattern : "))
print("\n")
search(pat, txt)
"""
/**********************************************************************************************************
OUTPUT:
Enter the text : AABAACAADAABAAABAA
Enter the pattern : AABA
Pattern found at index : 0
Pattern found at index : 9
Pattern found at index : 13
**********************************************************************************************************/
"""