Codeforces Beta Round #34 (Div. 2) C. Page Numbers

Source: Internet
Author: User

Codeforces Beta Round #34 (Div. 2) C. Page Numbers

 

C. Page Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

«Bersoft» company is working on a new version of its most popular text editor-Bord 2010. bord, like export other text editors, shocould 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 ).

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 shocould output this sequence in formatL1-R1,L2-R2 ,...,LK-RK, WhereRILatency + latency 1 latency <latencyLILifecycle + lifecycle 1 for allIFrom 1KAccept-limit 1, andLILimit ≤ limitRI. The new sequence shoshould 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, shoshould be ignored. if for some elementIFrom the new sequenceLISignature = SignatureRI, This element shoshould be outputLI, And not «LIAccept-Encoding-LI».

For example, sequence, 2 shocould be output as 1.

Input

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.

Output

Output the sequence in the required format.

Sample test (s) Input
1,2,3,1,1,2,6,6,2
Output
1-3,6
Input
3,2,1
Output
1-3
Input
30,20,10
Output
10,20,30

 

Link: http://codeforces.com/problemset/problem/34/C

Give a group of numbers. If there is a continuous number string such as 1, 2, 3, 4, output 1-4; otherwise, output a single number, such as 1, 2, 3, 10, output 1-3, 10

Solution: sort and de-duplicate, just simulate it. The input format is processed. Comparison questions ~

The Code is as follows:

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include using namespace std; int a [105]; int main (void) {int n = 0, r = 0, l = 0; // initialize the Left and Right subscripts char x; while (scanf (% d, & a [n ++]) {scanf (% c, & x); if (x = '') // if you enter a line break, end input break;} sort (a, a + n); n = unique (a, a + n)-a; for (int I = 1; I
    
     
L) printf (% d-% d, a [l], a [r]); else printf (% d, a [l]); printf (, n );}
    
   
  
 


 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.