Skip to content

Instantly share code, notes, and snippets.

@flymio
Created September 28, 2018 07:08
Show Gist options
  • Save flymio/9d77e05b80a436546d6d8c2aba6c3b38 to your computer and use it in GitHub Desktop.
Save flymio/9d77e05b80a436546d6d8c2aba6c3b38 to your computer and use it in GitHub Desktop.
Из чужих решений узнал про функцию bcdiv:
string bcdiv ( string $dividend , string $divisor [, int $scale = 0 ] )
Операция деления для чисел произвольной точности
<?php
// Complete the plusMinus function below.
function plusMinus($arr) {
$plus = 0;
$minus = 0;
$zero = 0;
$n = count($arr);
foreach($arr as $value){
if ($value>0){
$plus++;
}
else if ($value<0){
$minus++;
}
else{
$zero++;
}
}
printf("%0.06f\n",$plus/$n);
printf("%0.06f\n",$minus/$n);
printf("%0.06f\n",$zero/$n);
}
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $n);
fscanf($stdin, "%[^\n]", $arr_temp);
$arr = array_map('intval', preg_split('/ /', $arr_temp, -1, PREG_SPLIT_NO_EMPTY));
plusMinus($arr);
fclose($stdin);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment