#C7620. Counting Satisfying Elements
Counting Satisfying Elements
Counting Satisfying Elements
You are given an array of integers and a predicate condition. Your task is to count the number of elements in the array that satisfy the given condition.
The predicate condition is provided as a string and can be one of the following:
- even: Count numbers that are even. An integer \( n \) is even if \( n \mod 2 = 0 \).
- odd: Count numbers that are odd. An integer \( n \) is odd if \( n \mod 2 \neq 0 \).
- positive: Count numbers that are greater than zero.
Read the input from stdin
and output the result to stdout
.
inputFormat
The first line contains an integer \( n \), the number of elements in the array.
The second line contains \( n \) space-separated integers.
The third line contains a string which represents the predicate condition (even
, odd
, or positive
).
You should read from stdin
.
outputFormat
Output a single integer which is the count of numbers in the array that satisfy the specified condition. Write the answer to stdout
.
3
2 4 6
even
3