2개의 배열을 비교하여 높은쪽에 point 추가
2개의 point를 배열로 return
Sample Input 0
5 6 7
3 6 10
Sample Output 0
1 1
Sample Input 1
17 28 30
99 16 8
Sample Output 1
2 1
My Code :
// Complete the compareTriplets function below.
function compareTriplets($a, $b) {
$a_point = 0;
$b_point = 0;
for($i=0; $i<3; $i++) {
if($a[$i] > $b[$i]) {
$a_point++;
} else if($a[$i] < $b[$i]) {
$b_point++;
}
}
return [
$a_point,
$b_point
];
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$a_temp = rtrim(fgets(STDIN));
$a = array_map('intval', preg_split('/ /', $a_temp, -1, PREG_SPLIT_NO_EMPTY));
$b_temp = rtrim(fgets(STDIN));
$b = array_map('intval', preg_split('/ /', $b_temp, -1, PREG_SPLIT_NO_EMPTY));
$result = compareTriplets($a, $b);
fwrite($fptr, implode(" ", $result) . "\n");
fclose($fptr);