#102. 替换零值:右侧最大奇数

    ID: 102 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp5前缀和

替换零值:右侧最大奇数

Replace Zeros

Background

Dawei is working with an array of integers. He wants to perform some special modifications on the array to meet specific conditions.

Problem Description

Return a version of the given array where each zero value in the array is replaced by the largest odd value to the right of the zero in the array. If there is no odd value to the right of the zero, leave the zero as a zero.

Input Format

Input is given from Standard Input in the following format.

A single line containing several space-separated integers, representing the given array.

Output Format

Output to Standard Output in the following format.

Output a single line containing the elements of the modified array, separated by commas and spaces, enclosed in square brackets [].

Sample

[0 5 0 3]
[5, 5, 3, 3]
[0 4 0 3]
[3, 4, 3, 3]
[0 1 0]
[1, 1, 0]

Sample Explanation

For Sample 1 [0 5 0 3]:

  • The first 0 has odd numbers 5 and 3 to its right. The largest odd number among them is 5, so the first 0 is replaced by 5.
  • The second 0 has the odd number 3 to its right. The largest odd number among them is 3, so the second 0 is replaced by 3.
  • Other elements in the array remain unchanged. The final result is [5, 5, 3, 3].

Constraints

Time Limit: 1s, Memory Limit: 1024KiB.