Guest User

Untitled

a guest
Feb 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll ;
  4. typedef unsigned long long ull ;
  5. #define pb push_back
  6. #define all(v) (v).begin(), (v).end()
  7. #define mp make_pair
  8. #define rep(i,a,b) for (int i = a; i < b; i++)
  9. #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  10. void time ()
  11. {
  12. cout<<endl<<"Clock ticks: "<<clock()<<" Seconds: "<<(double)clock()/CLOCKS_PER_SEC*1000;
  13. }
  14. //-std=c++0x
  15.  
  16. int main() {
  17.  
  18. string x ;
  19. while (cin >> x )
  20. {
  21. deque <string> output ;
  22. string sum = "";
  23. bool status = false ;
  24. rep(i,0,x.size())
  25. {
  26. if (x[i] == '[')
  27. {
  28. if (!status && sum !="") output.push_front(sum);
  29. else if (status && sum != "") output.push_back(sum);
  30. status = false;
  31. sum = "" ;
  32. }
  33. else if ( x[i] == ']')
  34. {
  35. if (status && sum !="") output.push_back(sum) ;
  36. else if (!status && sum !="") output.push_front(sum) ;
  37. status = true ;
  38. sum = "";
  39. }
  40. else
  41. {
  42. sum+= x[i] ;
  43. }
  44. }
  45. if (sum !="")
  46. {
  47. if (!status && sum !="") output.push_front(sum);
  48. else if (status && sum != "") output.push_back(sum);
  49. }
  50. while (!output.empty())
  51. {
  52. cout<<output.front();
  53. output.pop_front();
  54. }
  55. cout<<endl;
  56. }
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment