fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4.  
  5. std::string EditLine(std::string Command){
  6. std::string ret;
  7. int Cur = 0;
  8.  
  9. for (std::size_t i = 0; i < Command.size(); i++){
  10.  
  11. if (Command[i] == '['){
  12. Cur--;
  13. continue;
  14. }
  15. if (Command[i] == ']'){
  16. Cur++;
  17. continue;
  18. }
  19. auto ins = std::inserter(ret, ret.begin()+ (Cur++));
  20. ins = Command[i];
  21. }
  22. return ret;
  23. }
  24.  
  25. int main(){
  26. std::string str = "abc[-[[/";
  27. std::string str2 = "a[b[c]]d";
  28. std::string R;
  29.  
  30. R = EditLine(str);
  31. std::cout << str << " -> " << R << std::endl;
  32. R = EditLine(str2);
  33. std::cout << str2<< " -> " << R << std::endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
abc[-[[/ -> a/b-c
a[b[c]]d -> cbad