34C.md (1954B)
1 Source: https://codeforces.com/problemset/problem/34/C 2 3 C. Page Numbers 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). 22 23 Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format *l*1-*r*1,*l*2-*r*2,...,*l**k*-*r**k*, where *r**i* + 1 < *l**i* + 1 for all *i* from 1 to *k* - 1, and *l**i* ≤ *r**i*. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element *i* from the new sequence *l**i* = *r**i*, this element should be output as *l**i*, and not as «*l**i* - *l**i*». 24 25 For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6. 26 27 Input 28 29 The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row. 30 31 Output 32 33 Output the sequence in the required format. 34 35 Examples 36 37 Input 38 39 ``` 40 1,2,3,1,1,2,6,6,2 41 ``` 42 43 Output 44 45 ``` 46 1-3,6 47 ``` 48 49 Input 50 51 ``` 52 3,2,1 53 ``` 54 55 Output 56 57 ``` 58 1-3 59 ``` 60 61 Input 62 63 ``` 64 30,20,10 65 ``` 66 67 Output 68 69 ``` 70 10,20,30 71 ```