Untitled
unknown
php
2 years ago
1.1 kB
2
Indexable
<?php $elements = []; while (FALSE !== ($line = fgets(STDIN))) { $elements[] = trim($line); } $intArray = []; $floatArray = []; $strArray = []; // $arr = [$intArray, $floatArray, $strArray]; foreach ($elements as $key) { if ( is_numeric($key) ) { $num = (float)$key; ( str_contains($key, ".") ) ? array_push($floatArray, $key) : array_push($intArray, $key); } else { array_push($strArray, $key); } } $printLine = "integers: "; sort($intArray); foreach ($intArray as $int) { $printLine = $printLine.$int.", "; } echo trim($printLine, ", "). PHP_EOL; $printLine = "floats: "; sort($floatArray); foreach ($floatArray as $float) { $printLine = $printLine.$float.", "; } echo trim($printLine, ", "). PHP_EOL; $printLine = "strings: "; sort($strArray ); foreach ($strArray as $str) { $printLine = $printLine.$str.", "; } echo trim($printLine, ", "). PHP_EOL; ?>