记录编号 608043 评测结果 AAAAAAAAAA
题目名称 4036.解压缩 最终得分 100
用户昵称 Gravatar我常常追忆未来 是否通过 通过
代码语言 C++ 运行时间 0.027 s
提交时间 2025-10-23 07:24:18 内存使用 3.72 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
stack<string>d;
stack<int>pre;
string s,t;
string ans;
int main(){
	cin>>s;
	for(int i=0;i<s.size();){
		if(isdigit(s[i])){
			int num=0;
			while(i<s.size()&&isdigit(s[i])){
				num=num*10+s[i]-'0';
				i++;
			}
			pre.push(num);
		} 
		else if(s[i]=='['){
			d.push(ans);
			ans="";
			i++;
		}
		else if(s[i]==']'){
			string now=d.top();
			d.pop();
			int tot=pre.top();
			pre.pop();
			while(tot--){
				now+=ans;
			}
			ans=now;
			i++;
		}
		else{
			ans+=s[i];
			i++;
		}
	}
	cout<<ans;

	return 0;
}