Find the time which is palindromic and comes after the given time | Function to return the required time ; To store the resultant time ; Hours are stored in h as integer ; Minutes are stored in m as integer ; Reverse of h ; Reverse of h as a string ; If MM < reverse of ( HH ) ; 0 is added if HH < 10 ; 0 is added if rev_h < 10 ; Increment hours ; Reverse of the hour after incrementing 1 ; 0 is added if HH < 10 ; 0 is added if rev_h < 10 ; Driver code
< ? php function getTime ( $ s , $ n ) { $ res = " " ; $ h = intval ( $ s . substr ( 0 , 2 ) ) ; $ m = intval ( $ s . substr ( 3 , 2 ) ) ; $ rev_h = ( $ h % 10 ) * 10 + ( ( $ h % 100 ) - ( $ h % 10 ) ) / 10 ; $ rev_hs = strval ( $ rev_h ) ; if ( $ h == 23 && $ m >= 32 ) { $ res = " - 1" ; } else if ( $ m < $ rev_h ) { $ temp = " " ; if ( $ h < 10 ) $ temp = "0" ; $ temp = $ temp . strval ( $ h ) ; if ( $ rev_h < 10 ) $ res = $ res . $ temp . " : 0" . $ rev_hs ; else $ res = $ res . $ temp . " : " . $ rev_hs ; } else { $ h ++ ; $ rev_h = ( $ h % 10 ) * 10 + ( ( $ h % 100 ) - ( $ h % 10 ) ) / 10 ; $ rev_hs = strval ( $ rev_h ) ; $ temp = " " ; if ( $ h < 10 ) $ temp = "0" ; $ temp = $ temp . strval ( $ h ) ; if ( $ rev_h < 10 ) $ res = $ res . $ temp . " : 0" . $ rev_hs ; else $ res = $ res . $ temp . " : " . $ rev_hs ; } return $ res ; } $ s = "21:12" ; $ n = strlen ( $ s ) ; echo getTime ( $ s , $ n ) ; return 0 ; ? >