-
Notifications
You must be signed in to change notification settings - Fork 0
/
CW.py
69 lines (57 loc) · 1.42 KB
/
CW.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
suff = {}
pref = {}
def main():
local_len = -1
tmp = ''
tmp1 = ''
adadadadadadadadadadadadadadada = ''
adadadadadadadadadadadadadada = ''
with open("CW.py") as f:
file = f.readlines()
for line in file:
for word in line.split(' '):
func(word)
for suf in suff.keys():
if suf in pref:
if len(suf) > local_len and suff[suf] != pref[suf]:
local_len = len(suf)
tmp = suff[suf]
tmp1 = pref[suf]
print(tmp, tmp1, local_len)
def func(word):
suf = ''
prf = ''
iter = 0
while (suf != word):
suf = word[0:iter]
prf = word[-iter:]
iter += 1
suff[suf] = word
pref[prf] = word
def func1(line1, line2):
pref = ''
suf = ''
iter1 = 0
iter2 = len(line2) - 1
if (len(line1) == 0 or len(line2) == 0):
return 0
while (iter1 != len(line1) and iter2 >= 0):
if (line1[iter1] != line2[iter2]):
return iter1
iter1 += 1
iter2 -= 1
return iter1
def main1():
dict = {}
with open("wwww.txtx", encoding="utf8") as f:
text = f.read()
for line in text:
for word in line:
if word in dict:
dict[word] += 1
else:
dict[word] = 1
for key in dict:
print(dict[key])
if __name__ == "__main__":
main()