HDU 1274 展开字符串
2011-01-21 19:19
435 查看
#include <iostream> using namespace std; char input[250005]; char str[250005]; int main() { int cas; #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif scanf("%d", &cas); while (cas--) { scanf("%s", input); int len; while (1) { int flag = 0; int c = 0; int i, j, k; len = strlen(input); for (i = 0; i < len; ++i) { if (input[i] >= 'a' && input[i] <= 'z') { str[c++] = input[i]; } else if (input[i] >= '0' && input[i] <= '9') { int cnt = 0; while (input[i] >= '0' && input[i] <= '9') { cnt *= 10; cnt += input[i] - '0'; ++i; } if (input[i] != '(') { while (cnt--) { str[c++] = input[i]; } } else { int t = 1; int temp = i + 1; while (t != 0) { if (input[temp] == '(') { ++t; } if (input[temp] == ')') { --t; } ++temp; } for (j = 0; j < cnt; ++j) { for (k = i + 1; k < temp - 1; ++k) { str[c++] = input[k]; if (input[k] == '(' || input[k] == ')' || (input[k] >= '0' && input[k] <= '9')) { flag = 1; } } } i = temp - 1; } } } str[c] = 0; memcpy(input, str, sizeof(str)); if (flag == 0) { break; } } cout << str << endl; } return 0; }
相关文章推荐
- hdu 1274 展开字符串
- hdu 1274 展开字符串
- CSU-ACM2017暑期训练3-递推与递归 G - 展开字符串 HDU - 1274
- hdu 1274 展开字符串 栈 stack 处理
- HDU 1274(展开字符串)
- hdu 1274 展开字符串
- hdu 1274展开字符串(用栈来实现的)
- hdu 1274 展开字符串
- (HDU - 1274 )展开字符串
- CSU-ACM2017暑期训练3-递推与递归 G - 展开字符串 HDU - 1274
- HDU 1274(展开字符串)
- HDU - 1274 展开字符串 递归
- HDU 1274 展开字符串 (递归+string类)
- HDU 1274 展开字符串(深搜+字符串,显示缩写的字符串)
- hdu——1274——展开字符串
- HDU - 1274 展开字符串
- hdu 1274 展开字符串(栈)
- HDU 1274 展开字符串 (递归+string类)
- HDU - 1274: 展开字符串(递归,栈模拟)
- HDU 1274 展开字符串(递归)