CiscoOA #12
Compact the List
估计简单可在线判题
Given a strictly increasing list of integers, output each maximal run of consecutive integers as a to b, and output a single-element run as just that element. Runs keep their original order.
输入格式
The first line contains n, followed by n strictly increasing integers. The original gave no numeric bounds; this site adds 0≤n≤100000 and −10^9≤a[i]≤10^9. An empty list produces empty output text.
输出格式
Output one line per maximal consecutive run: a single item is written as a, and two or more items as a to b. An empty list produces empty output text.
样例 1
输入:
7
1 2 3 6 8 9 10
输出:
1 to 3
6
8 to 10
样例 2
输入:
4
-2 -1 0 2
输出:
-2 to 0
2
样例 3
输入:
0
输出:
样例说明
The outputs of the three public examples are, in order: 1 to 3 / 6 / 8 to 10; -2 to 0 / 2; empty text. Verified by independent enumeration or direct simulation.