From 077e10ff5047e4562832599dec2bc5dca5f45d08 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 8 Mar 2024 09:35:26 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 54 ++++++------------------------------------------------ 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/main.cpp b/main.cpp index e68b31b..975fe2f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,47 +1,10 @@ #include - -using namespace std; - -/****************************************************************************** - - Online C++ Compiler. - Code, Compile, Run and Debug C++ program online. -Write your code in this editor and press "Run" button to compile and execute it. - -https://www.onlinegdb.com/online_c++_compiler - -*******************************************************************************/ - #include #include #include #include -// std::string kek(std::string strIn, int pos = 0) -// { -// std::cout << strIn << std::endl; - -// for (int i = pos; i < strIn.size(); i++) -// { -// std::string strNum; -// if (std::isdigit(static_cast(strIn[i]))) -// { // Если число -// while (true) -// { -// strNum += strIn[i++]; -// if (strIn[i] == '[') -// break; // Буквы или цифры начнутся со следующей буквы -// } -// auto repeat = std::atoi(strNum.c_str()); -// std::cout << repeat << std::endl; - -// } -// } - -// return "return"; -// } - -std::string decode(std::string& strIn, std::string::iterator& itr) +std::string decode(std::string& strIn, std::string::iterator& itr, bool firstCircle = false) { std::string out; @@ -50,8 +13,6 @@ std::string decode(std::string& strIn, std::string::iterator& itr) std::string strNum; auto repeat = 1; - auto itr_char = *itr; // DELME - if (std::isdigit(static_cast(*itr))) { while (*itr != '[') @@ -59,17 +20,16 @@ std::string decode(std::string& strIn, std::string::iterator& itr) strNum += *itr++; } repeat = std::atoi(strNum.c_str()); - // std::cout << repeat << std::endl; // DELME - auto tmp = decode(strIn, ++itr); + auto rptOut = decode(strIn, ++itr); for (int i = 0; i < repeat; ++i) - out += tmp; - + out += rptOut; } if (*itr == ']') { - return out; // нужно будет вернуть подстроку + if (!firstCircle) + return out; } else out += *itr; @@ -85,7 +45,7 @@ std::string kek(std::string strIn) std::cout << strIn << std::endl; auto itr = strIn.begin(); - return decode(strIn, itr); + return decode(strIn, itr, true); } int main() @@ -107,7 +67,5 @@ int main() strIn = "3[b15[a]]"; std::cout << kek(strIn) << std::endl; - // std::string wait; - // std::cin >> wait; return 0; }