/*http://acm.nit.net.cn/showproblem.jsp?pid=1022*/ #include <stdio.h> #include <ctype.h> #define MAXSIZE 250; char * unfoldstr(char *); int main() { int n, i; char str[250]; while(scanf("%d",&n) == 1) { for(i=0; i < n; i++) { scanf("%s", str); unfoldstr(str); } } return 0; } char * unfoldstr(char * str) { int i; char * end = NULL; int num; while(*str) { if(isdigit(*str)) { num = 0; while(isdigit(*str)) { num= num * 10 + *str - '0'; str++; } end = str; str++; for(i = 0; i < num; i++) { if((*end) == '(') { str = unfoldstr(end+1); } else { putchar(*end); } } } if(isalpha(*str)) { putchar(*str); ++str; } if(*str == ')') { str++; return str; } if(*str == '\0' ) { putchar('\n'); break; } } }