-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutomaticTrading.py
47 lines (32 loc) · 912 Bytes
/
AutomaticTrading.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
val=str(input())
length=len(val)
lq=int(input())
# create suffix array
suffixArr=[-1]*(length)
def createSuffixArray(string, index):
if string=="" or index>len(suffixArr):
return
suffixArr[index]=string
t=index+1
createSuffixArray(string[1:],t )
LCP={}
def findLCP(first, second):
prev=suffixArr[first]
curr=suffixArr[second]
match=0
for j in range(len(curr)):
if j==len(prev):
break
if prev[j]==curr[j]:
match+=1
else:
break
LCP[(first, second)]=match
createSuffixArray(val, 0)
# print(suffixArr)
for i in range(lq):
start,end=list(map(int, input().split(" ")))
if not (start>len(val) or end>len(val) or start>end):
if len(suffixArr)!=0:
findLCP(start, end)
print(LCP[(start, end)])