Find the final radiations of each Radiated Stations | Function to print the final radiations ; Function to create the array of the resultant radiations ; Resultant radiations ; Declaring index counter for left and right radiation ; Effective radiation for left and right case ; Radiation for i - th station ; Radiation increment for left stations ; Radiation increment for right stations ; Print the resultant radiation for each of the stations ; 1 - based indexing
< ? php function print_radiation ( $ rStation , $ n ) { for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { echo $ rStation [ $ i ] . " " ; } echo " STRNEWLINE " ; } function radiated_Station ( $ station , $ n ) { $ rStation = array ( ) ; $ rStation = array_fill ( 0 , $ n + 1 , 0 ) ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ li = $ i - 1 ; $ ri = $ i + 1 ; $ lRad = $ station [ $ i ] - 1 ; $ rRad = $ station [ $ i ] - 1 ; $ rStation [ $ i ] += $ station [ $ i ] ; while ( $ li >= 1 && $ lRad >= 1 ) { $ rStation [ $ li -- ] += $ lRad -- ; } while ( $ ri <= $ n && $ rRad >= 1 ) { $ rStation [ $ ri ++ ] += $ rRad -- ; } } print_radiation ( $ rStation , $ n ) ; } $ station = array ( 0 , 7 , 9 , 12 , 2 , 5 ) ; $ n = ( sizeof ( $ station ) / sizeof ( $ station [ 0 ] ) ) - 1 ; radiated_Station ( $ station , $ n ) ; ? >