Minimum Deci | C ++ Program to implement the above approach ; Function to find the count of minimum Deci - Binary numbers required to obtain S ; Stores the minimum count ; Iterate over the string s ; Convert the char to its equivalent integer ; If current character is the maximum so far ; Update the maximum digit ; Print the required result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minimum_deci_binary_number ( string s ) { int m = INT_MIN ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { int temp = s [ i ] - '0' ; if ( temp > m ) { m = temp ; } } return m ; } int main ( ) { string S = "31" ; cout << minimum_deci_binary_number ( S ) ; return 0 ; }