#188. 提取数组中前N个偶数
提取数组中前N个偶数
Extract First N Even Numbers
Background
Congcong is learning array operations and has encountered a task that requires filtering specific elements from an integer array.
Problem Description
Given an array of positive integers, and an integer . Return a new array of length containing the first even numbers from the original array. It is guaranteed that the original array will contain at least even numbers.
Input Format
Input is given from standard input in the following format.
A single line containing several positive integers. The first part represents the elements of array (space-separated), and the last integer represents .
Output Format
Output is printed to standard output in the following format.
A single line representing the new array, containing the first even numbers from the original array. Array elements are separated by commas and spaces, and enclosed in square brackets
[].
Sample
3 2 4 5 8 2
[2, 4]
3 2 4 5 8 3
[2, 4, 8]
6 1 2 4 5 8 3
[6, 2, 4]
Sample Explanation
Sample 1: Input array [3 2 4 5 8] and . The even numbers in the original array are in order. Taking the first even numbers yields [2, 4].
Sample 2: Input array [3 2 4 5 8] and . The even numbers in the original array are in order. Taking the first even numbers yields [2, 4, 8].
Sample 3: Input array [6 1 2 4 5 8] and . The even numbers in the original array are in order. Taking the first even numbers yields [6, 2, 4].
Constraints
Time limit: 1s, Memory limit: 1024KB.