#C12714. Index Parity Detection
Index Parity Detection
Index Parity Detection
You are given an array of integers. Your task is to determine the indices where even and odd numbers occur within the array.
Specifically, you need to output a dictionary with two keys: even
and odd
. The value corresponding to even
is a list of 0-indexed positions at which the array elements are even, while the value corresponding to odd
is a list of positions for odd numbers.
If the array is empty, both lists should be empty. For example, if the input array is [10, 23, 36, 41, 52, 65]
, the output should be {"even": [0, 2, 4], "odd": [1, 3, 5]}
.
Note: Your program should read the input from standard input and print the result to standard output.
inputFormat
The first line contains an integer n (0 ≤ n ≤ 105), representing the number of elements in the array. The second line contains n space-separated integers.
outputFormat
Output a JSON-formatted dictionary with two keys: even
and odd
. The value associated with even
should be a list of indices where even numbers occur, and the value for odd
should be a list of indices where odd numbers occur.
6
10 23 36 41 52 65
{"even": [0, 2, 4], "odd": [1, 3, 5]}