题目地址:​​点击打开链接​

思路:深搜+字符串,直接看代码

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>//islower的头文件

using namespace std;

char a[300];

void dfs(int left,int right)
{
int i,j,count1,count2,l,r;
for(i=left; i<=right; i++)
{
if(a[i] >= '1' && a[i] <= '9')
{
count1 = a[i] - '0';
l = r = i + 1;
if(a[l] == '(')//这里还有可能直接是字母,不是括号,所以要判断
{
count2 = 1;
for(j=l+1; j<=right; j++)
{
if(a[j] == '(')
count2++;
else if(a[j] == ')')
count2--;
if(count2 == 0)
{
r = j;
break;
}
}
}
for(j=1; j<=count1; j++)
{
dfs(l,r);
}
i = r;//这里不用加1,for循环会加1
}
else if(islower(a[i]))
{
printf("%c",a[i]);
}
}
}

int main()
{
int t,len;
scanf("%d",&t);
while(t--)
{
scanf("%s",a);
len = strlen(a);
dfs(0,len-1);
printf("\n");
}
return 0;
}