https://leetcode-cn.com/problems/decode-string/
思路:stack
string decodeString(string s) {
stack<char> st;
string res = "";
for (int i = 0;i < s.size(); i++) {
if (s[i] == ']') {
string temp = "";
while(!st.empty() && st.top()!= '[') {
temp += st.top();
st.pop();
}
string num = "";
st.pop();
while(!st.empty() && st.top() >= '0' && st.top() <= '9') {
num = st.top() + num;
st.pop();
}
string new_temp = "";
int n = atoi(num.c_str());
for (int j = 0; j < n; j++) {
new_temp = new_temp + temp;
}
//cout << n << temp << endl;
for (int j = new_temp.size() - 1; j >= 0; j--) {
st.push(new_temp[j]);
}
} else {
st.push(s[i]);
}
}
while(!st.empty()) {
res = st.top() + res;
st.pop();
}
return res;
}