#include #include #include #include #include std::string decode(std::string& strIn, std::string::iterator& itr, bool firstCircle = false) { std::string out; while (itr != strIn.end()) { std::string strNum; auto repeat = 1; if (std::isdigit(static_cast(*itr))) { while (*itr != '[') { strNum += *itr++; } repeat = std::atoi(strNum.c_str()); auto rptOut = decode(strIn, ++itr); for (int i = 0; i < repeat; ++i) out += rptOut; } if (*itr == ']') { if (!firstCircle) return out; } else out += *itr; ++itr; } return out; } std::string kek(std::string strIn) { std::cout << strIn << std::endl; auto itr = strIn.begin(); return decode(strIn, itr, true); } int main() { std::string strIn; strIn = "3[a2[c]]"; std::cout << kek(strIn) << std::endl; strIn = "c2[a]3[b]c"; std::cout << kek(strIn) << std::endl; strIn = "c2[a3[b]]c"; std::cout << kek(strIn) << std::endl; strIn = "231[ab]"; std::cout << kek(strIn) << std::endl; strIn = "3[b15[a]]"; std::cout << kek(strIn) << std::endl; return 0; }