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++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t; cin >> t;
- while (t--) {
- string s ;
- cin >> s;
- bool z = false , o = true ;
- for ( int i = 0 ; i < s.size() ; i++) {
- if (s[i] == '0'){
- z = false ;
- o = true ;
- }
- if (s[i] == '1'){
- z = true ;
- o = false;
- }
- if (s[i] == '0' || s[i] =='1') cout <<s[i] ;
- else if (s[i] =='?' && z == false ) cout <<"0";
- else if (s[i] =='?' && o == false ) cout <<"1";
- }
- cout <<'\n';
- }
- return 0 ;
- }
No comments