Maximize the missing values in given time in HH : MM format | C ++ program for the above approach ; Function to find the maximum time by replacing ' ? ' by any digits ; If the 0 th index is ' ? ' ; If the 1 st index is ' ? ' ; If the 3 rd index is ' ? ' ; If the 4 th index is ' ? ' ; Return new string ; Driver Code
#include <iostream> NEW_LINE using namespace std ; void maxTime ( string s ) { if ( s [ 0 ] == ' ? ' ) { if ( s [ 1 ] <= '3' s [ 1 ] == ' ? ' ) s [ 0 ] = '2' ; else s [ 0 ] = '1' ; } if ( s [ 1 ] == ' ? ' ) { if ( s [ 0 ] != '2' ) { s [ 1 ] = 9 ; } else s [ 1 ] = 3 ; } if ( s [ 3 ] == ' ? ' ) s [ 3 ] = '5' ; if ( s [ 4 ] == ' ? ' ) s [ 4 ] = '9' ; cout << s << endl ; } int main ( ) { string S = " ? 4:5 ? " ; maxTime ( S ) ; return 0 ; }