1.题目要求
输入:HG[3|B[2|CA]]F
输出:HGBCACABCACABCACAF
2.解体思路
使用栈来解决“[]”的层次调用,一个栈保存压缩时的次数,另一个栈来保存压缩的字符串。
遍历输入的字符串,根据栈是否为空,和根据当前不同字符的种类进行不同的操作。字母、数字、[、]、|五种情况。
3.解题代码
#include<iostream>
#include<string>
#include<stack>
using namespace std;
void unCompress(string str){
stack<int> times; //各层次括号中次数
stack<string> str_temp; //各层次括号中需解压缩的
string temp="";
string res="";
int length = str.size();
int num = 0;
for(