#34. 提取数组首元素
提取数组首元素
Extract First Elements of Arrays
Background
Dawei is processing some data and needs to extract key information from two arrays.
Problem Description
Given two integer arrays, and , of any length, return a new array with the first element of each array. If either array is length , ignore that array.
Input Format
The input consists of a single line. This line contains two strings representing integer arrays, where elements of each array are space-separated and enclosed in square brackets []. The two array strings are separated by a single space.
[element1 element2 ...][element1 element2 ...]
Output Format
Output a new array containing the extracted elements. Elements are comma-separated and enclosed in square brackets [].
[element1, element2]
Sample
[1 2 3] [7 9 8]
[1, 7]
[1] [2]
[1, 2]
[1 7] []
[1]
Sample Explanation
For the first sample, the first element of array is , and the first element of array is . Merging them results in [1, 7].
Constraints
Time limit: s, Memory limit: KiB for each test case.