3
22/10/2024 4:51 pm
Argomento iniziale
Write a program to find all the top integers in an array. A top integer is an integer which is bigger than all the elements to its right. Print the biggest number and all the numbers after it.
Examples:
1 risposta
2
22/10/2024 4:52 pm
The solution:
<?php $array = array_map('intval', explode(' ', readline())); $count = count($array); $topInteger = []; for ($row = 0; $row < $count; $row++) { $top = true; for ($i = $row + 1; $i < $count; $i++) { if ($array[$row] <= $array[$i]) { $top = false; break; } } if ($top) { $topInteger[] = $array[$row]; } } echo implode(' ', $topInteger);