File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ def decode_string (s ):
2+ stack = []
3+ curr_num = 0
4+ curr_str = ""
5+ i = 0
6+ while i < len (s ):
7+ if s [i ].isdigit ():
8+ num = 0
9+ # Handle numbers with more than one digit
10+ while i < len (s ) and s [i ].isdigit ():
11+ num = num * 10 + int (s [i ])
12+ i += 1
13+ curr_num = num
14+ elif s [i ] == "{" or s [i ] == "(" :
15+ # Push current status into stack and reset
16+ stack .append ((curr_str , curr_num ))
17+ curr_str = ""
18+ curr_num = 0
19+ i += 1
20+ elif s [i ] == "}" or s [i ] == ")" :
21+ # Pop from stack and decode
22+ last_str , num = stack .pop ()
23+ curr_str = last_str + curr_str * num
24+ i += 1
25+ else :
26+ curr_str += s [i ]
27+ i += 1
28+ return curr_str
29+
30+
31+ specialString = input ()
32+ print (decode_string (specialString ))
You can’t perform that action at this time.
0 commit comments