AccurateLee | Codeforces Round 652 (Div 2) | Code Solution

AccurateLee | Codeforces Round 652 (Div 2) | Code Solution


C++ code given below:



  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int n;
  10. cin>>n;
  11. string s;
  12. cin>>s;
  13. int flag=0;
  14. for(int i=0;i<s.length()-1;i++)
  15. {
  16. if(s[i]=='1' && s[i+1]=='0')
  17. {
  18. flag=1;
  19. break;
  20. }
  21. }
  22. if(flag==0)
  23. cout<<s<<endl;
  24. else
  25. {
  26. for(int i=0;i<s.length();i++)
  27. {
  28. if(s[i]=='0')
  29. cout<<"0";
  30. else
  31. {
  32. cout<<"0";
  33. break;
  34. }
  35. }
  36. for(int i=s.length()-1;i>=0;i--)
  37. {
  38. if(s[i]=='1')
  39. cout<<"1";
  40. else
  41. break;
  42. }
  43. }
  44. cout<<endl;
  45. }
  46. }

Comments

Popular posts from this blog

Number of non-unique elements hackerrank - Python

Top 5 Programming Languages You Should Learn in 2020 [Jobs]

Map in c++ - Standard Template Library (STL)