题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
stack<int> nums;
stack<char> ops;
stack<string> srs;
string res = "";
void cal()
{
string v = "";
int a = nums.top(); nums.pop();
string b = srs.top(); srs.pop();
while(a --) v += b;
srs.push(v);
if(srs.size() > 1)
{
res = srs.top();
srs.pop();
res = srs.top() + res;
srs.pop();
srs.push(res);
}
}
int main()
{
string s;
cin >> s;
for(int i = 0; i < s.size(); i ++)
{
char c = s[i];
if(c >= '0' && c <= '9')
{
int j = i, v = 0;
while(j < s.size() && s[j] >= '0' && s[j] <= '9')
{
v = v * 10 + s[j] - '0';
j ++;
}
i = j - 1;
nums.push(v);
}
else if(c == '[')
{
ops.push(c);
}
else if(c == ']')
{
if(ops.top() == '[') cal();
ops.pop();
}
else if(c >= 'a' && c <= 'z')
{
int k = i;
string sr = "";
while(k < s.size() && s[k] >= 'a' && s[k] <= 'z')
{
sr = sr + s[k];
//sr = s[j] + sr;
k ++;
}
i = k - 1;
srs.push(sr);
}
}
if(srs.size() > 1)
{
string srt = srs.top();
srs.pop();
srt = srs.top() + srt;
srs.push(srt);
}
cout << srs.top() << endl;
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla