标签:
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): 1958 Accepted Submission(s): 929
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 20 int main() { int t, i, j, x, y, h, m, num, p, k, f, b[N]; char s[N], s1[N], s2[N]; scanf("%d", &t); while(t--) { m = 0; scanf("%s", s); for(i = 0 ; s[i] != ‘\0‘ ; i++) if(s[i] == ‘(‘) m++; while(m--) { k = j = h = 0; num = 0; memset(s1, 0, sizeof(s1)); memset(s2, 0, sizeof(s2)); memset(b, 0, sizeof(b)); for(i = 0 ; s[i] != ‘\0‘ ; i++) if(s[i] == ‘(‘) x = i; for(i = x + 1 ; s[i] != ‘\0‘ ; i++) { if(s[i] == ‘)‘) { y = i; break; } s2[k++] = s[i]; } for(i = x - 1 ; i >= 0 ; i--) { if(s[i] >= ‘0‘ && s[i] <= ‘9‘) b[j++] = s[i] - ‘0‘; else break; } s[x - j] = ‘\0‘; for(i = y + 1 ; s[i] != ‘\0‘ ; i++) s1[h++] = s[i]; for(i = 0 ; i < j ; i++) num = num * 10 + b[i]; strcat(s, s2); num--; if(num > 0) { while(num--) strcat(s, s2); } strcat(s, s1); } p = f = 0; for(i = 0 ; s[i] != ‘\0‘ ; i++) { if(s[i] >= ‘0‘ && s[i] <= ‘9‘) { p = p * 10 + (s[i] - ‘0‘); f = 1; } if(f == 1) i++; else if(s[i] >= ‘a‘ && s[i] <= ‘z‘) { p = 0; printf("%c", s[i]); } while(p--) printf("%c", s[i]); p = f = 0; } printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4708264.html