-
Notifications
You must be signed in to change notification settings - Fork 0
/
1066.php
34 lines (27 loc) · 1.07 KB
/
1066.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
// beecrowd | 1066
// Even, Odd, Positive and Negative
// Adapted by Neilor Tonin, URI Brazil
// Timelimit: 1
// Make a program that reads five integer values. Count how many of these values are even, odd, positive and negative. Print these information like following example.
// Input
// The input will be 5 integer values.
// Output
// Print a message like the following example with all letters in lowercase, indicating how many of these values are even, odd, positive and negative.
$numbers = [];
for ($i = 0; $i < 5; $i++) {
$numbers[] = intval(fgets(STDIN));
}
$count = [
'par' => ['count' => 0, 'name' => 'par(es)'],
'impar' => ['count' => 0, 'name' => 'impar(es)'],
'positivo' => ['count' => 0, 'name' => 'positivo(s)'],
'negativo' => ['count' => 0, 'name' => 'negativo(s)'],
];
foreach($numbers as $number){
$count[($number % 2 == 0) ? 'par' : 'impar']['count']++;
$count[($number > 0) ? 'positivo' : 'negativo']['count'] += ($number != 0 ) ? 1 : 0;
}
foreach($count as $type){
echo $type['count']." valor(es) " . $type['name'] . "\n";
}