显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
string a;
string solve(int l,int r)
{
int poi,i,temp,num,right=1;
string ans,tempans;
for (poi=l;poi<=r;poi++)
{
if (a[poi]=='[')
{
temp=1;
for (i=poi+1;;i++)
{
if (a[i]=='[')
temp++;
else if (a[i]==']')
{
temp--;
if (temp==0)
break;
}
}
tempans=solve(poi+1,i-1);
/**/ans+=tempans;
poi=i;
// for (i=1;i<=right;i++)
// ans+=tempans;
// right=1;
//continue;
}
else if (a[poi]>='0'&&a[poi]<='9')
{
for (i=poi+1;;i++)
if (a[i]<'0'||a[i]>'9')
break;
i--;
temp=i;
num=0;
for (i=poi;i<=temp;i++)
num=num*10+a[i]-'0';
poi=temp;
right=num;
//continue;
}
else// if (a[poi]=='A'&&a[poi]<='Z')
{
for (i=poi+1;;i++)
if (a[i]<'A'||a[i]>'Z')
break;
i--;
tempans=a.substr(poi,i-poi+1);
/**/ans+=tempans;
poi=i;
// for (i=1;i<=right;i++)
// ans+=tempans;
// right=1;
//continue;
}
}
tempans=ans;
for (i=1;i<right;i++)
ans+=tempans;
return(ans);
}
int main(void)
{
freopen("passworda.in","r",stdin);
freopen("passworda.out","w",stdout);
int len;
string ans;
cin>>a;
len=a.length();
ans=solve(0,len-1);
cout<<ans<<endl;
return(0);
}