string decodeString(string s) {
int num=0;
string str="";
stack<int> numstk;
stack<string> strstk;
for(int i=0;i<(int)s.size();++i){
if(s[i]>='0'&&s[i]<='9'){
num=10*num+s[i]-'0';
}
else if(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'){
str+=s[i];
}
else if(s[i]=='['){
numstk.push(num);
num=0;
strstk.push(str);
str="";
}
else if(s[i]==']'){
int time=numstk.top();
numstk.pop();
for(int i=0;i<time;++i)
strstk.top()+=str;
str=strstk.top();
strstk.pop();
}
}
return str;
}
394. 字符串解码/C++
最新推荐文章于 2022-12-04 11:00:42 发布