Codeforces Round #652 (Div. 2) 1369B. AccurateLee Solution
Problem Link: https://codeforces.com/problemset/problem/1369/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************/
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ll n,t,i;
- cin>>t;
- while(t--)
- {
- string s1,s2;
- cin>>n>>s1;
- s2=s1;
- sort(s1.begin(),s1.end());
- if(s1==s2||s1.size()==1)
- cout<<s2<<endl;
- else
- {
- int lzero=0,lone=0;
- for(i=0; i<s2.size(); i++)
- {
- if(s2[i]!='1')
- lzero++;
- else
- break;
- }
- for(i=s2.size()-1; i>=0; i--)
- {
- if(s2[i]!='0')
- lone++;
- else
- break;
- }
- for(i=0; i<=lzero; i++)
- cout<<"0";
- for(i=0; i<lone; i++)
- cout<<"1";
- cout<<endl;
- }
- }
- }
No comments