Skip to content
Author: loop3r
Date: 20260225
tag: 递归
link: https://www.luogu.com.cn/problem/P1928

问题描述

link

分析

参考代码

cpp
string dfs() {
    string s = "", X;
    char c;
    int D;

    while (cin >> c) { // 读入字符
        if (c == '[') {
            cin >> D;
            X = dfs(); // 递归处理 X
            while (D--) s += X; // X 重复 D 次
        } else if (c == ']') {
            return s;
        } else {
            s += c;
        }
    }

    return s;
}