题目:
分析:leetcode之前做过。代码质量应该有提高。
代码:
#include<bits/stdc++.h>
using namespace std;
int x;
string s;
string f()
{
//[ ] 中的第一个字母是是数字
int c=s[x]-'0';
x++;
if(s[x]>='0'&&s[x]<='9') {
c=c*10;
c=c+s[x]-'0';
x++;
}
string ans;
for(;x<s.length();x++)
{
if(s[x]=='[') {
x++;
ans+=f();
}
if(s[x]==']') {
x++;
string st;
for(int i=0;i<c;i++) st+=ans;
//cout<<ans<<"-------";
return st;
}
ans+=s[x];
}
}
int main()
{
cin>>s;
x=0;
for(;x<s.length();)
{
if(s[x]=='[') {
x++; cout<<f();
}
else
{
cout<<s[x]; x++;
}
}
}