fork download
  1. #include<iostream>
  2. #include<deque>
  3. using namespace std;
  4. deque<string> q;
  5.  
  6. void trans(string x){
  7. if(x.length()>0){
  8. if(x[0]=='['){
  9. int i =1;
  10. while(x[i]!='[' && x[i]!= ']' && i<x.length())i++;
  11. q.push_front(x.substr(1,i-1));
  12. trans(x.substr(i)+"");
  13. return;
  14. }else if(x[0]==']'){
  15. int i =1;
  16. while(x[i]!='[' && x[i]!= ']' && i<x.length())i++;
  17. q.push_back(x.substr(1,i-1));
  18. trans(x.substr(i));
  19. return;
  20. }else{
  21. char h[]={x[0]};
  22. string hh(h);
  23. q.push_back(hh);
  24. trans(x.substr(1));
  25. return;
  26. }
  27. }
  28. }
  29.  
  30. int main(){
  31. string xs;
  32. cin>>xs;
  33. trans(xs);
  34. deque<string>::iterator it = q.begin();
  35. while(it!= q.end())
  36. cout<<*it++;
  37.  
  38. }
Success #stdin #stdout 0s 4384KB
stdin
This_is_a_[Beiju]_text
stdout
BeijuT�����h@����i�����s@����_�����i@����s�����_@����a�����_@����_text