Codeforces Round #652 (Div. 2) 1369B. AccurateLee Solution


 

Problem Link: https://codeforces.com/problemset/problem/1369/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************/
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define ll long long int
  10. int main()
  11. {
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(0);
  14. ll n,t,i;
  15. cin>>t;
  16. while(t--)
  17. {
  18. string s1,s2;
  19. cin>>n>>s1;
  20. s2=s1;
  21. sort(s1.begin(),s1.end());
  22. if(s1==s2||s1.size()==1)
  23. cout<<s2<<endl;
  24. else
  25. {
  26. int lzero=0,lone=0;
  27. for(i=0; i<s2.size(); i++)
  28. {
  29. if(s2[i]!='1')
  30. lzero++;
  31. else
  32. break;
  33. }
  34. for(i=s2.size()-1; i>=0; i--)
  35. {
  36. if(s2[i]!='0')
  37. lone++;
  38. else
  39. break;
  40. }
  41. for(i=0; i<=lzero; i++)
  42. cout<<"0";
  43. for(i=0; i<lone; i++)
  44. cout<<"1";
  45.  
  46. cout<<endl;
  47. }
  48. }
  49. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.