Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll ;
- typedef unsigned long long ull ;
- #define pb push_back
- #define all(v) (v).begin(), (v).end()
- #define mp make_pair
- #define rep(i,a,b) for (int i = a; i < b; i++)
- #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- void time ()
- {
- cout<<endl<<"Clock ticks: "<<clock()<<" Seconds: "<<(double)clock()/CLOCKS_PER_SEC*1000;
- }
- //-std=c++0x
- int main() {
- string x ;
- while (cin >> x )
- {
- deque <string> output ;
- string sum = "";
- bool status = false ;
- rep(i,0,x.size())
- {
- if (x[i] == '[')
- {
- if (!status && sum !="") output.push_front(sum);
- else if (status && sum != "") output.push_back(sum);
- status = false;
- sum = "" ;
- }
- else if ( x[i] == ']')
- {
- if (status && sum !="") output.push_back(sum) ;
- else if (!status && sum !="") output.push_front(sum) ;
- status = true ;
- sum = "";
- }
- else
- {
- sum+= x[i] ;
- }
- }
- if (sum !="")
- {
- if (!status && sum !="") output.push_front(sum);
- else if (status && sum != "") output.push_back(sum);
- }
- while (!output.empty())
- {
- cout<<output.front();
- output.pop_front();
- }
- cout<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment