-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_D.py
94 lines (84 loc) · 1.59 KB
/
Task_D.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import re
def get_sec_rec(a,b,r):
c = b.copy()
for i in c:
a[len(a)-len(b)]=i
if len(b)>1:
b.remove(i)
get_sec_rec(a,b,r)
b.append(i)
else:
r.append(a.copy())
def get_sec(n):
a = []
b = []
for i in range(n):
a.append(0)
b.append(i+1)
r = []
get_sec_rec(a,b,r)
return(r)
def subs_present_in_key(subs, key):
for i in range(len(subs)):
if key.find(subs[i]) < 0:
return(False)
return(True)
def calc(d):
ry = 'YES'
rn = 'NO'
promo = d[0]
key = d[1]
subs_l = d[2]
promo_l = len(promo)
key_l = len(key)
if False:
if subs_l <= 1:
return(rn)
if (promo_l < 6 or promo_l > 30):
return(rn)
if (key_l < 6 or key_l > 30):
return(rn)
if promo_l % subs_l > 0:
return(rn)
if subs_l >= key_l:
return(rn)
promo_check = re.search('[A-Z0-9]*', promo)
if promo_check.group() != promo:
return(rn)
subs = []
i = 0
while i < promo_l:
subs.append(promo[i:i + subs_l])
i += subs_l
#print(subs)
if not subs_present_in_key(subs, key):
return(rn)
r = rn
for a in get_sec(len(subs)):
#print(a)
k = [key]
for i in a:
s = subs[i-1]
#print(k)
#print(k.find(s), end=' ')
for j in range(len(k)):
p = k[j].find(s)
if p > -1:
tmp = k[j]
k.pop(j)
k.append(tmp[:p])
k.append(tmp[p + subs_l:])
break
else:
break
else:
r = ry
break
return(r)
if __name__ == '__main__':
promo_l = int(input())
promo = input()
key_l = int(input())
key = input()
subs_l = int (input())
print(calc([promo, key, subs_l]))