Back
Close

Page Numbers

Statement

 Goal

Many applications allow you to specify a range of pages for printing: 1-2,5,7-9.
Convert a list of random page numbers p into the above format.
Input
Line 1: An integer n for the number of pages.
Line 2: Space separated list of n page numbers p in random order.
Output
Comma separated ordered list of pages p with consecutive pages pn,..., pm printed as pn-pm.
Constraints
1 ≤ n ≤ 99
1 ≤ p ≤ 99
Example
Input
6
1 2 5 7 8 9
Output
1-2,5,7-9

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1: Example Test
Input
6 1 2 5 7 8 9
Output
1-2,5,7-9

Validator 1: Single Pages Validator
Input
4 7 5 16 2
Output
2,5,7,16

Test 2: Page Groups Test
Input
9 1 2 3 4 5 12 13 14 15
Output
1-5,12-15

Validator 2: Page Groups Validator
Input
7 1 2 3 15 16 17 18
Output
1-3,15-18

Test 3: Mixed Test
Input
14 5 7 28 10 26 11 12 13 21 25 27 29 30 31
Output
5,7,10-13,21,25-31

Validator 3: Mixed Validator
Input
15 15 33 60 17 30 31 57 32 61 51 55 56 58 59 62
Output
15,17,30-33,51,55-62

Test 4: Mixed with Doublettes Test
Input
9 31 5 7 2 3 6 18 30 32
Output
2-3,5-7,18,30-32

Validator 4: Mixed with Doublettes Validator
Input
10 24 8 7 76 26 6 75 9 25 2
Output
2,6-9,24-26,75-76

Solution language

Solution

Stub generator input