Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Solution 1
- #include<bits/stdc++.h>
- using namespace std;
- void solve(string &s){
- bool f=true;
- stack<char> a,t;
- queue<char> b;
- for(char &i:s){
- if(i=='['){
- f=false;
- while(!t.empty()){
- a.emplace(t.top());
- t.pop();
- }
- }else if(i==']') f=true;
- else if(f) b.emplace(i);
- else t.emplace(i);
- }
- while(!t.empty()){
- a.emplace(t.top());
- t.pop();
- }
- while(!a.empty()){
- cout<<a.top();
- a.pop();
- }
- while(!b.empty()){
- cout<<b.front();
- b.pop();
- }
- cout<<'\n';
- }
- int main(){
- std::ios_base::sync_with_stdio(0);
- cin.tie(0);
- string s;
- while(cin>>s) solve(s);
- return 0;
- }
- /*
- //Solution 2:
- #include<bits/stdc++.h>
- using namespace std;
- void solve(string &s){
- bool f=true;
- stack<string> a;
- string b="",t="";
- for(char &i:s){
- if(i=='['){
- f=false;
- a.emplace(t);
- t="";
- }else if(i==']') f=true;
- else if(f) b+=i;
- else t+=i;
- }
- if(t!="") a.emplace(t);
- while(!a.empty()){
- cout<<a.top();
- a.pop();
- }
- cout<<b<<'\n';
- }
- int main(){
- std::ios_base::sync_with_stdio(0);
- cin.tie(0);
- string s;
- while(cin>>s) solve(s);
- return 0;
- }
- */
- /*
- Zero Judge i524. 11988: Broken Keyboard (a.k.a. Beiju Text)
- https://zerojudge.tw/ShowProblem?problemid=i524
- 2024 September 24
- Solution 1: AC (7ms, 324KB)
- Solution 2: AC (2ms, 348KB)
- */
Advertisement
Add Comment
Please, Sign In to add comment