比赛 20251022赛前模拟1 评测结果 AAAAAAAAAA
题目名称 解压缩 最终得分 100
用户昵称 淮淮清子 运行时间 0.028 s
代码语言 C++ 内存使用 3.73 MiB
提交时间 2025-10-22 08:34:02
显示代码纯文本
#include <iostream>
#include <string>
#include <stack>
using namespace std;

string s;
stack<int> rep;
stack<string> sub;
string sum = "";

void dfs(){
    int n = s.size();
    int i = 0;
    while(i < n){
        if(isdigit(s[i])){
            int as = 0;
            while (i < n && isdigit(s[i])){
                as = as * 10 + (s[i] - '0');
                i ++;
            }
            rep.push(as);
        }
        else if(s[i] == '['){
            sub.push(sum);
            sum = "";
            i ++;
        }
        else if (s[i] == ']'){
            string temp = sub.top(); sub.pop();
            int cnt = rep.top(); rep.pop();
            while(cnt --) temp += sum;
            sum = temp;
            i ++;
        }
        else{
            sum += s[i];
            i ++;
        }
    }
    return;
}

int main(){
	freopen("extract.in", "r", stdin);
	freopen("extract.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
    cin >> s;
    dfs();
    cout << sum << '\n';
    return 0;
}