Skip to content

Instantly share code, notes, and snippets.

@z-rui
Created July 14, 2019 06:39
Show Gist options
  • Save z-rui/50ab273e13f8fd29c67bfa6043d1c6ce to your computer and use it in GitHub Desktop.
Save z-rui/50ab273e13f8fd29c67bfa6043d1c6ce to your computer and use it in GitHub Desktop.
Expand "2[ab3[c]]" into "abcccabccc"
char*f(char*s){char*t;int n;for(t=s;*t;t++)if(*t==']')break;
else if(*t>>4==3){for(n=*(s=t++)-48;*t>>4==3;n=n*10+(*t++-48));
if(*t=='[')for(s=t+1;n--;t=f(s));else for(t--;s<=t;putchar(*s++));}
else putchar(*t);return t;}int main(int c,char**v){f(v[1]);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment