fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.  
  8. string a;
  9. cin >> a;
  10. stack<char> s;
  11. string save = "";
  12. for(char c: a){
  13. if(c == '<'){
  14. if(!s.empty()){
  15. save = save+s.top();
  16. s.pop();
  17. }
  18. continue;
  19. }
  20. if(c == '>'){
  21. if(save.length()>0){
  22. s.push(save[save.length()-1]);
  23. save.pop_back();
  24. }
  25. continue;
  26. }
  27. if(c == '-'){
  28. s.pop();
  29. continue;
  30. }
  31. if(c!= '<' || c!='>' || c!='-')
  32. s.push(c);
  33. }
  34. while(save.length()>0){
  35. s.push(save[save.length()-1]);
  36. save.pop_back();
  37. }
  38. string res ="";
  39. while(!s.empty()){
  40. res = s.top() + res;
  41. s.pop();
  42. }
  43. cout << res;
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5320KB
stdin
wheree-yourdreamcome<<<<s>>>>true
stdout
whereyourdreamscometrue