递归函数处理问题类型
#include<bits/stdc++.h>
using namespace std;
string read(){
string s,st;
char c;
int n;
while(cin>>c){
if(c=='['){
cin>>n;
st=read();
while(n--)
s+=st;
}
else if(c==']'){
return s;
}
else{
s+=c;
}
}
}
int main()
{
cout<<read();
return 0;
}
对于这类问题可以写一个递归输入函数,而不是输入完再处理。
对于每一个[ ]都为一个函数处理
浙公网安备 33010602011771号