显示代码纯文本
#include<cstdio>
#include<stack>
#include<cstring>
#include<iostream>
using namespace std;
string sr;
stack<int> num;
stack<string> str;
int check=0;
inline void work()
{
char ch;
int x;
while(scanf("%c",&ch)==1)
{
if(ch=='\n') break;
if(check>0){
string ss="";
while(ch!=']'&&ch!='['){
ss+=ch;
scanf("%c",&ch);
}
str.push(ss);
}
if(ch=='['){
check++;
scanf("%d",&x);
num.push(x);
str.push("[");
}
if(ch==']'){
check--;
x=num.top();
num.pop();
string sb="";
while(!str.empty()){
string ss=str.top();
str.pop();
if(ss=="[") break;
sb+=ss;
}
string s1=sb;
sb="";
for(int i=1; i<=x; i++) sb+=s1;
str.push(sb);
}
if(check<=0)
while(!str.empty()){
if(str.top()!="[") sr+=str.top();
str.pop();
}
if(ch!='['&&ch!=']') sr+=ch;
}
cout<<sr;
}
int Main()
{
freopen("passworda.in","r",stdin);
freopen("passworda.out","w",stdout);
work();
fclose(stdin);
fclose(stdout);
return 0;
}
int wsr=Main();
int main(){;}