3
28/10/2024 6:37 pm
Onderwerp starter
Write a program which creates 2 arrays. You will be given an integer n. On the next n lines you get 2 integers.
Form 2 arrays as shown below:
1 antwoord
2
28/10/2024 6:39 pm
My solution:
<?php $number = intval(readline()); $arrZig = []; $arrZag = []; for ($i = 0; $i < $number; $i++) { $args = explode(' ', readline()); if ($i % 2 == 0) { $arrZig[] = $args[0]; $arrZag[] = $args[1]; } else { $arrZig[] = $args[1]; $arrZag[] = $args[0]; } } echo implode(' ', $arrZig) . PHP_EOL; echo implode(' ', $arrZag);
Inloggen of Registreren aub om op dit onderwerp te reageren.