You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1023 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
//因为不知道什么时候结束所以需要输入后回车然后CTRL+D结束
/**思路:递归的特点就是只解决一层的问题,同样问题依赖于递归调用。
1[
2]
3,cin>>D,
4
*/
string dfs() {
string s, p;
int t;
char x;
while (cin >> x) {
if (x == '[') {
//后面必须跟着数字!
cin >> t;//读取这个数字
//递归调用
p = dfs();
//拼接t次
while (t--) s += p;
} else if (x == ']')
return s;//返回调用者
//读取X的每个字符
else s += x;
}
return s;
}
int main() {
cout << dfs();
return 0;
}