【洛谷】P1928 外星密码

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string dx(){
    int d;
    char c;
    string s = "", tmp;
    while (cin >> c){
        if (c == '['){
            cin >> d;
            tmp = dx();
            while (d--) s += tmp;
        }
        else if (c == ']') return s;
        else s += c;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    cout << dx();
    return 0;
}

版权声明:本文为weixin_43359312原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。