We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
<?php/* * Complete the 'plusMinus' function below. * * The function accepts INTEGER_ARRAY arr as parameter. */functionplusMinus($arr){$positivi=0;$negativi=0;$base0=0;$dimensione=count($arr);foreach($arras$item){switch(true){case$item>0:$positivi++;break;case$item===0:$base0++;break;case$item<0:$negativi++;break;}}echosprintf("%.6f",$positivi/$dimensione)."\n";echosprintf("%.6f",$negativi/$dimensione)."\n";echosprintf("%.6f",$base0/$dimensione)."\n";}$n=intval(trim(fgets(STDIN)));$arr_temp=rtrim(fgets(STDIN));$arr=array_map('intval',preg_split('//',$arr_temp,-1,PREG_SPLIT_NO_EMPTY));plusMinus($arr);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
My PHP Solution: