Print Elements with Even Index
EasyPractice library · +10 XPqueuesimulationbasic iteration
Given a list of N integers, print the elements that are located at even indices (0, 2, 4, ...). The elements should be printed in the order they appear in the input list, separated by spaces.
Input
The first line contains an integer N, the number of elements. The second line contains N space-separated integers.
Output
Print the elements at even indices, separated by spaces.
Constraints
1 <= N <= 1000 Each integer will be between -1000 and 1000.
Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests
Example 1
Input
5 10 20 30 40 50
Output
10 30 50
Elements at indices 0, 2, 4 are 10, 30, 50.
Example 2
Input
3 -5 15 25
Output
-5 25
Elements at indices 0, 2 are -5, 25.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 10 20 30 40 50
Example 2 input
3 -5 15 25