Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- int main()
- {
- fast();
- ll t;
- cin>>t;
- while(t--)
- {
- ll n;
- cin>>n;
- string s,sub,x;
- cin>>s;
- ll i;
- for(i=n-1;i>=0;i--)
- {
- if(i==n-1 && s[i]=='1')
- {
- while(s[i]=='1')
- {
- x.push_back(s[i]);
- i--;
- }
- i++;
- }
- else
- {
- if(s[i]=='0')sub.push_back(s[i]);
- else
- {
- if(sub.size()>0)
- {
- sub.clear();
- sub.push_back('0');
- }
- }
- }
- }
- x+=sub;
- for(i=x.size()-1;i>=0;i--)cout<<x[i];
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment