#106. 数组重排:3后跟4

    ID: 106 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-3gesp4模拟排序

数组重排:3后跟4

Three Followed by Four

Background

Dawei is organizing a pile of numbers. He has a special preference: he wants every number 33 to be immediately followed by a number 44.

Problem Description

Given an array of integers, rearrange the elements such that every number 33 is immediately followed by a number 44. Note:

  1. The positions of numbers 33 cannot be moved.
  2. All other numbers may be moved.
  3. The array is guaranteed to contain the same number of 33s and 44s.
  4. It is guaranteed that every 33 is followed by a number that is not a 33.
  5. It is guaranteed that a 33 appears in the array before any 44.

Input Format

Input is given from standard input in the following format.

A single line containing several integers, separated by spaces, representing the elements of the original array.

Output Format

Output is printed to standard output in the following format.

A single line containing the rearranged array elements, separated by commas and enclosed in square brackets [].

Sample

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

Sample Explanation

For Sample 1: The original array is [1, 3, 1, 4]. The number 33 is at index 11. We need to place a 44 after it. The original 44 is at index 33. We can move the 44 to index 22, resulting in [1, 3, 4, 1].

Constraints

The time limit for each test case is 11 second, and the memory limit is 10241024 KiB.