Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- s = input()
- st_num = []
- st_s = []
- ok = False
- res = ''
- num = ''
- s1 = ''
- now = ''
- count = 0
- for c in s:
- if c == '(':
- ok = True
- if s1 != '':
- st_s.append(s1)
- s1 = ''
- if num != '':
- st_num.append(int(num))
- num = ''
- if st_s:
- b = st_s.pop()
- if count > 0:
- now += b
- res += b
- count += 1
- elif c == ')':
- count -= 1
- if s1 != '':
- st_s.append(s1)
- s1 = ''
- if num != '':
- st_num.append(int(num))
- num = ''
- if ok:
- ok = False
- n = st_num.pop()
- b = st_s.pop()
- res += n * b
- now += n * b
- elif st_s:
- b = st_s.pop()
- res += b
- now += b
- if count == 0:
- if st_num:
- res += (st_num.pop() - 1) * now
- now = ''
- elif c.isdigit():
- num += c
- if s1 != '':
- st_s.append(s1)
- s1 = ''
- else:
- s1 += c
- if num != '':
- st_num.append(int(num))
- num = ''
- while st_num:
- res *= st_num.pop()
- if s1:
- res += s1
- print(res)
Add Comment
Please, Sign In to add comment