Educational Codeforces Round 149 (Rated for Div. 2) 1837C - Best Binary String Solution


 

Problem Link : https://codeforces.com/problemset/problem/1837/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t; cin >> t;
  8. while (t--) {
  9. string s ;
  10. cin >> s;
  11. bool z = false , o = true ;
  12. for ( int i = 0 ; i < s.size() ; i++) {
  13. if (s[i] == '0'){
  14. z = false ;
  15. o = true ;
  16. }
  17. if (s[i] == '1'){
  18. z = true ;
  19. o = false;
  20. }
  21. if (s[i] == '0' || s[i] =='1') cout <<s[i] ;
  22. else if (s[i] =='?' && z == false ) cout <<"0";
  23. else if (s[i] =='?' && o == false ) cout <<"1";
  24. }
  25. cout <<'\n';
  26. }
  27. return 0 ;
  28. }

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 ...

Powered by Blogger.