#include
#include
using namespace std;
string Decode(string& s)
{
int i = 0;
int x = -1;
int y = -1;
int z = -1;
int sz = s.size();
while (i < sz)
{
if (s[i] == '[')
{
x = i;
}
else if (s[i] == ',')
{
y = i;
}
else if (s[i] == ']')
{
z = i;
break;
}
i += 1;
}
if (x != -1 && y != -1 && z != -1)
{
int times = (int(s[x + 1])) - 48;
string sub;
string sub_times ;
sub = s.substr(y + 1, z - (y + 1));
for (int i = 0; i < times; i++)
{
sub_times += sub;
}
string decode_str;
decode_str = s.substr(0, x) + sub_times + s.substr(z + 1, sz - (z + 1));
return Decode(decode_str);
}
return s;
}
int main()
{
string s;
cin >> s;
string decode_str;
decode_str = Decode(s);
cout << decode_str << endl;
}
你说的是 哪样的不能运行? 这段程序 要 输入 一个字符串,才能往后执行的。