#Really simple decompressor code

4 messages · Page 1 of 1 (latest)

amber scroll
#

Hi everyone! I've wanted to ask whether my code culture (and the algorithm itself) is good, because I feel like my previous knowledge of python is eating into my c++ code and making it pythonic, if that makes sense

Task on picture.

#include <string>
std::string sdf;
std::string spaceMessage(std::string str) {
    std::string decrypted;
    for (int i = 0; i<str.size(); i++){
        if (str.at(i) == '['){
            int count = str.at(i+1) - '0';
            int j = i;
            while (str.at(j) != ']'){
                j++;
            }
            for (int k = 0; k < count; k++){
                decrypted.append(str.substr(i+2, j - i - 2));
            }
            i = j;
        }
        else{
            if (str.at(i) != ']') {
                decrypted.push_back(str.at(i));
            }
            else {
            }
        }
    }
    return decrypted;
}
int main() {
    std::cout << spaceMessage("ABCD") << std::endl;
}```
pulsar flicker
#

there isnt a stack handling layers of bracket

eager granite