Minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B | C ++ implementation of the approach ; Function to return the minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B ; Initialize result ; Loop through last b digits ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findCount ( string s , int n , int a , int b ) { int res = 0 ; for ( int i = 0 ; i < b ; i ++ ) { if ( i == a ) res += ( s [ n - i - 1 ] != '1' ) ; else res += ( s [ n - i - 1 ] != '0' ) ; } return res ; } int main ( ) { string str = "1001011001" ; int N = str . size ( ) ; int A = 3 , B = 6 ; cout << findCount ( str , N , A , B ) ; return 0 ; }