|
| 1 | +<?php |
| 2 | + |
| 3 | +// Complete the countApplesAndOranges function below. |
| 4 | +function countApplesAndOranges($s, $t, $a, $b, $apples, $oranges) { |
| 5 | + |
| 6 | +$apple_catch = 0; |
| 7 | +$orange_catch = 0; |
| 8 | + |
| 9 | +foreach($apples as $apple){ |
| 10 | + if ($apple >= 0) { |
| 11 | + if ($apple+$a >=$s && $apple+$a <=$t) { |
| 12 | + $apple_catch++; |
| 13 | + } |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +foreach($oranges as $orange){ |
| 18 | + if($orange <= 0){ |
| 19 | + if($b+$orange <=$t && $b+$orange >=$s ){ |
| 20 | + $orange_catch++; |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | +} |
| 25 | + |
| 26 | +echo $apple_catch . "\n"; |
| 27 | +echo $orange_catch . "\n"; |
| 28 | + |
| 29 | +} |
| 30 | + |
| 31 | +$stdin = fopen("php://stdin", "r"); |
| 32 | + |
| 33 | +fscanf($stdin, "%[^\n]", $st_temp); |
| 34 | +$st = explode(' ', $st_temp); |
| 35 | + |
| 36 | +$s = intval($st[0]); |
| 37 | + |
| 38 | +$t = intval($st[1]); |
| 39 | + |
| 40 | +fscanf($stdin, "%[^\n]", $ab_temp); |
| 41 | +$ab = explode(' ', $ab_temp); |
| 42 | + |
| 43 | +$a = intval($ab[0]); |
| 44 | + |
| 45 | +$b = intval($ab[1]); |
| 46 | + |
| 47 | +fscanf($stdin, "%[^\n]", $mn_temp); |
| 48 | +$mn = explode(' ', $mn_temp); |
| 49 | + |
| 50 | +$m = intval($mn[0]); |
| 51 | + |
| 52 | +$n = intval($mn[1]); |
| 53 | + |
| 54 | +fscanf($stdin, "%[^\n]", $apples_temp); |
| 55 | + |
| 56 | +$apples = array_map('intval', preg_split('/ /', $apples_temp, -1, PREG_SPLIT_NO_EMPTY)); |
| 57 | + |
| 58 | +fscanf($stdin, "%[^\n]", $oranges_temp); |
| 59 | + |
| 60 | +$oranges = array_map('intval', preg_split('/ /', $oranges_temp, -1, PREG_SPLIT_NO_EMPTY)); |
| 61 | + |
| 62 | +countApplesAndOranges($s, $t, $a, $b, $apples, $oranges); |
| 63 | + |
| 64 | +fclose($stdin); |
0 commit comments