#31. 获取数组前两元素

    ID: 31 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-1gesp3一维数组条件结构

获取数组前两元素

Get First Two Elements

Background

Congcong is currently learning about array operations. He encountered a task that requires extracting a specific number of elements from a given array.

Problem Description

Given an integer array of any length, return a new array containing its first 22 elements. If the array is smaller than length 22, use whatever elements are present.

Input Format

Input is given from Standard Input in the following format.

The input consists of a single line representing an integer array. Array elements are space-separated and enclosed in square brackets [].

Output Format

Output is to Standard Output in the following format.

The output consists of a single line representing a new integer array. Array elements are separated by commas and spaces, and enclosed in square brackets [].

Sample

[1 2 3]
[1, 2]
[1 2]
[1, 2]
[1]
[1]

Sample Explanation

  • Sample 1: The original array is [1 2 3]. Its length is greater than 22, so the first two elements [1, 2] are returned.
  • Sample 2: The original array is [1 2]. Its length is equal to 22, so the first two elements [1, 2] are returned.
  • Sample 3: The original array is [1]. Its length is less than 22, so all existing elements [1] are returned.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.