This repository was archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.py
72 lines (56 loc) · 1.5 KB
/
9.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
import re
import sys
inputdata = sys.stdin.readline()
# inputdata = "A(1x5)BC"
data = inputdata
# data = [x.strip() for x in inputdata.split(",")]
# data = [(x[0], int(x[1:])) for x in data]
prog = re.compile(r'\((\d*)x(\d*)\)')
def krneki(s):
result = 0
i = 0
while i < len(s):
if s[i] == '(':
substr = s[i:]
m = prog.search(substr)
z, f, x, y = m.group(0), substr[len(m.group(0)):], int(m.group(1)), int(m.group(2))
# print z, f, x, y
# print f[:x]*y
# print z
result += krneki(f[:x])*y
i += len(z) + x
# print f[:x], x, y
else:
result += 1
i += 1
# print result
# i += 1
return result
print krneki(data)
# import re
# import sys
# inputdata = sys.stdin.readline()
# # inputdata = "A(1x5)BC"
# data = inputdata
# # data = [x.strip() for x in inputdata.split(",")]
# # data = [(x[0], int(x[1:])) for x in data]
# prog = re.compile(r'\((\d*)x(\d*)\)')
# result = 0
# i = 0
# while i < len(data):
# if data[i] == '(':
# substr = data[i:]
# m = prog.search(substr)
# z, f, x, y = m.group(0), substr[len(m.group(0)):], int(m.group(1)), int(m.group(2))
# # print z, f, x, y
# # print f[:x]*y
# # print z
# result += len(f[:x])*y
# i += len(z) + x
# # print f[:x], x, y
# else:
# result += 1
# i += 1
# # print result
# # i += 1
# print result