http://acm.hdu.edu.cn/showproblem.php?pid=1274
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2008 Accepted Submission(s): 957
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; #define N 1100 char s[N]; int DFS(int ith) { int k, e, i; for( i=ith; s[i] && s[i]!=‘)‘; i++) { for(k=0; s[i] && (s[i]>=‘0‘ && s[i]<=‘9‘); i++) k = k*10 + s[i]-‘0‘; if(!k) k = 1; if(s[i]==‘(‘) { while(k--) e = DFS(i+1); i = e; } else { while(k--) putchar(s[i]); } } if(s[i]==‘)‘) return i; } int main() { int t; scanf("%d", &t); while(t--) { scanf("%s", s); DFS(0); printf("\n"); } return 0; }
原文:http://www.cnblogs.com/YY56/p/4876656.html