Saleh127

uva 11988

Jun 24th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. fellow_junior
  9. string a;
  10. ll i,j,k,l,e,f;
  11. while(cin>>a)
  12. {
  13. string c="";
  14. stack<string>beiju;
  15. l=a.size();
  16. for( i=0; i<l; )
  17. {
  18. if(a[i]=='[')
  19. {
  20. i++;
  21. string d="";
  22. while(1)
  23. {
  24. if(a[i]!='[' && a[i]!=']' && i<l)
  25. {
  26. d+=a[i];
  27. i++;
  28. }
  29. else break;
  30. }
  31. if(d.size()>0) beiju.push(d);
  32. }
  33. else if(a[i]==']')
  34. {
  35. i++;
  36. }
  37. else c+=a[i],i++;
  38. }
  39. while(beiju.empty()==0)
  40. {
  41. cout<<beiju.top();
  42. beiju.pop();
  43. }
  44. cout<<c<<endl;
  45. }
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment