-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax.py
More file actions
26 lines (22 loc) Β· 652 Bytes
/
max.py
File metadata and controls
26 lines (22 loc) Β· 652 Bytes
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
def split_balanced_string(S):
count = 0
balanced_strings = []
curr_count_L = 0
curr_count_R = 0
for char in S:
if char == 'L':
curr_count_L += 1
elif char == 'R':
curr_count_R += 1
if curr_count_L == curr_count_R:
balanced_strings.append(S[:curr_count_L + curr_count_R])
count += 1
S = S[curr_count_L + curr_count_R:]
curr_count_L = 0
curr_count_R = 0
return count, balanced_strings
S = input().strip()
count, balanced_strings = split_balanced_string(S)
print(count)
for string in balanced_strings:
print(string)