Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string fun (int &idx, string &str)
- {
- string res = "";
- string decoded_string = "";
- while (idx < str.size())
- {
- if (isdigit(str[idx]))
- {
- string num ="";
- while ( idx < str.size() && isdigit(str[idx] ) )
- num += str[idx++];
- int t = stoi (num);
- idx++;
- decoded_string = fun (idx,str);
- for (int ttimes = 1 ; ttimes <= t ; ttimes++)
- res += decoded_string;
- }
- else if (isalpha(str[idx]) )
- res+= str[idx];
- else if (str[idx] == ']')
- return res;
- idx++;
- }
- return res;
- }
- string decodeString(string s) {
- int idx = 0 ;
- return fun (idx ,s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement