Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*! Input Count */
- $countNum = intval(readline());
- /*! Numbers array & input array */
- $numbers = array('odd' => ['min' => 'No', 'max' => 'No', 'sum' => 0.0], 'even' => ['min' => 'No', 'max' => 'No', 'sum' => 0.0]);
- $input = array();
- /*! If $countNum has value different than 0 or null */
- if($countNum) {
- /*! Insert values into temporary array */
- for($index = 0; $index < $countNum; $index++) {
- $number = floatval(readline());
- array_push($input, $number);
- /*! Set Min and Max */
- $numbers[$number & 1 ? 'odd' : 'even']['min'] = $number;
- $numbers[$number & 1 ? 'odd' : 'even']['max'] = $number;
- }
- /*! Organize the main array */
- for($index = 0; $index < $countNum; $index++) {
- /*! Set type */
- $type = ($input[$index] & 1 ? 'odd' : 'even');
- /*! Increment the sum */
- $numbers[$type]['sum'] += $input[$index];
- /*! Check for Min */
- if($input[$index] < $numbers[$type]['min'])
- $numbers[$type]['min'] = $input[$index];
- /*! Check for Max */
- if($input[$index] > $numbers[$type]['max'])
- $numbers[$type]['max'] = $input[$index];
- }
- }
- printf('Odd Sum: ' . $numbers['odd']['sum'] . PHP_EOL);
- printf('Odd Min: ' . $numbers['odd']['min'] . PHP_EOL);
- printf('Odd Max: ' . $numbers['odd']['max'] . PHP_EOL);
- printf('Even Sum: ' . $numbers['even']['sum'] . PHP_EOL);
- printf('Even Min: ' . $numbers['even']['min'] . PHP_EOL);
- printf('Even Max: ' . $numbers['even']['max'] . PHP_EOL);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement