#include <iostream>
#include <string>
#include <algorithm>
std::string EditLine(std::string Command){
std::string ret;
int Cur = 0;
for (std::size_t i = 0; i < Command.size(); i++){
if (Command[i] == '['){
Cur--;
continue;
}
if (Command[i] == ']'){
Cur++;
continue;
}
auto ins = std::inserter(ret, ret.begin()+ (Cur++));
ins = Command[i];
}
return ret;
}
int main(){
std::string str = "abc[-[[/";
std::string str2 = "a[b[c]]d";
std::string R;
R = EditLine(str);
std::cout << str << " -> " << R << std::endl;
R = EditLine(str2);
std::cout << str2<< " -> " << R << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKc3RkOjpzdHJpbmcgRWRpdExpbmUoc3RkOjpzdHJpbmcgQ29tbWFuZCl7CglzdGQ6OnN0cmluZyByZXQ7CglpbnQgQ3VyID0gMDsKCglmb3IgKHN0ZDo6c2l6ZV90IGkgPSAwOyBpIDwgQ29tbWFuZC5zaXplKCk7IGkrKyl7CgoJCWlmIChDb21tYW5kW2ldID09ICdbJyl7CgkJCUN1ci0tOwoJCQljb250aW51ZTsKCQl9CgkJaWYgKENvbW1hbmRbaV0gPT0gJ10nKXsKCQkJQ3VyKys7CgkJCWNvbnRpbnVlOwoJCX0KCQlhdXRvIGlucyA9IHN0ZDo6aW5zZXJ0ZXIocmV0LCByZXQuYmVnaW4oKSsgKEN1cisrKSk7CgkJaW5zID0gQ29tbWFuZFtpXTsKCX0KCXJldHVybiByZXQ7Cn0KCmludCBtYWluKCl7CglzdGQ6OnN0cmluZyBzdHIgPSAiYWJjWy1bWy8iOwoJc3RkOjpzdHJpbmcgc3RyMiA9ICJhW2JbY11dZCI7CglzdGQ6OnN0cmluZyBSOwoKCVIgPSBFZGl0TGluZShzdHIpOwoJc3RkOjpjb3V0IDw8IHN0ciA8PCAiIC0+ICIgPDwgUiA8PCBzdGQ6OmVuZGw7CglSID0gRWRpdExpbmUoc3RyMik7CglzdGQ6OmNvdXQgPDwgc3RyMjw8ICIgLT4gIiA8PCBSIDw8IHN0ZDo6ZW5kbDsKCglyZXR1cm4gMDsKfQ==