You are given an array of integers. Your task is to write a program that splits this array into exactly four parts (or quarters).
The division rule is as follows:
Calculate the base size for each part by dividing the total number of elements, N, by 4 using integer division (part_size = N / 4).
The first three parts will each contain part_size elements.
The fourth part will contain all the remaining elements. This means if N is not perfectly divisible by 4, the last part will be larger than the others.
If the array has fewer than four elements, some of the first three parts may be empty.
The first line contains a single integer N, the number of elements in the array.
The second line contains N space-separated integers, representing the elements of the array.
Print four lines, each representing one part of the split array.
The elements in each part should be separated by spaces.
If a part is empty, print a blank line.
This problem tests your understanding of integer arithmetic and array/slice manipulation. The core of the solution lies in correctly calculating the indices for slicing the original array.
6
1 2 3 4 5 6
1
2
3
4 5 6
Total elements N = 6.
Base part size = 6 / 4 = 1.
Part 1 gets 1 element: 1.
Part 2 gets 1 element: 2.
Part 3 gets 1 element: 3.
Part 4 gets the rest: 4 5 6.
9
1 2 3 4 5 6 7 8 9
1 2
3 4
5 6
7 8 9
Total elements N = 9.
Base part size = 9 / 4 = 2.
Part 1 gets 2 elements: 1 2.
Part 2 gets 2 elements: 3 4.
Part 3 gets 2 elements: 5 6.
Part 4 gets the rest: 7 8 9.
The expected time complexity is O(N).
0 <= N <= 1000
-1000 <= array element <= 1000
Time limit: 1 sec