#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string src;
void exp(int sbegin, int send)
{
int i;
for(i=sbegin; i<send; i++)
{
if(src[i] !='[')
{
cout<<src[i];
continue;
}
int times=0, beg, end = send-1;
for(beg=i+1; src[beg]>='0'&&src[beg]<='9'; beg++)
{
times*=10;
times+=src[beg]-'0';
}
while(src[end] != ']') end--;
i=end;
for(int j=0; j<times; j++) exp(beg, end);
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>src;
exp(0, src.size());
return 0;
}
评测记录
谢谢大家