#K76997. Group Consecutive Numbers
Group Consecutive Numbers
Group Consecutive Numbers
You are given a list of integers and your task is to group them into sublists where each sublist contains consecutive integers (i.e. numbers where the difference between consecutive elements is 1). For example, if the input list is [1, 2, 3, 7, 8, 10, 11, 12, 14]
, the correct grouping is [[1, 2, 3], [7, 8], [10, 11, 12], [14]]
.
Note that the order of the numbers in the input is preserved, so non-sorted lists should be processed in the given order. If the list is empty, no output should be produced.
inputFormat
The input is given via standard input (stdin). The first line contains an integer n, representing the number of integers in the list. If n > 0, the second line contains n integers separated by single spaces.
outputFormat
Print the groups of consecutive numbers to standard output (stdout). Each group should be printed on a separate line with its numbers separated by single spaces. If there are no numbers in the input (i.e. the list is empty), output nothing.## sample
9
1 2 3 7 8 10 11 12 14
1 2 3
7 8
10 11 12
14
</p>