forwhat00  
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string input;
string f(){
    string tempstr;tempstr[0]=0;
    char t;
    int n;
    while(cin>>t){
        if(t!='['){
            if(t!=']'){
                tempstr+=t;
            }else{
                return tempstr;
            }
        }else{
            cin>>n;
            string temp=f();
            while(n--)tempstr+=temp;
        }
    }
    return tempstr;
}
int main() {
    cout<<f();
    return 0;
}

https://www.luogu.com.cn/problem/P1928

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string input;
string f(){
 string tempstr;tempstr[0]=0;
 char t;
 int n;
 while(cin>>t){
  if(t!='['){
   if(t!=']'){
    tempstr+=t;
   }else{
    return tempstr;
   }
  }else{
   cin>>n;
   string temp=f();
   while(n--)tempstr+=temp;
  }
 }
 return tempstr;
}
int main() {
 cout<<f();
 return 0;
}

posted on 2020-07-03 16:13  forwhat00  阅读(262)  评论(0编辑  收藏  举报