您的位置:首页 > 其它

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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  input include c