HDU 1106 sorting is actually string segmentation

Source: Internet
Author: User

Problem Description: enter a number in a row. If we regard '5' in this row as a space, several non-negative integers (some integers may start with '0, the '0' of these headers should be ignored unless the integer is composed of several '0' and the integer is 0 ).

Your task is to sort the generated integers in ascending order.


The Input contains multiple groups of test cases. Each group of Input data has only one row of numbers (no space between numbers), and the length of this line of numbers is not greater than 1000.

Input data guarantee: The calculated non-negative integer is not greater than 100000000, and the input data cannot all be composed of '5.

For each test case, Output results are sorted by integers. Two Adjacent integers are separated by a space. Each group occupies one row.

Sample Input
0051231232050775

Sample Output
0 77 12312320

The sorting is not a problem because the maximum number cannot exceed the integer.

Is how to split the string.

Details:

1 consecutive 5?

5 at the beginning of 2?

3 end with 5?

4. The end is not 5. Do not miss the ending number.


Simple questions. Relax.

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include using namespace std; int main () {string strs; while (cin> strs) {int num = 0; vector
     
      
Vi; int I = 0; for (; I <(int) strs. size () & strs [I] = '5'; I ++); for (; I <(int) strs. size ();) {if ('5' = strs [I]) {vi. push_back (num); num = 0; for (I ++; I <(int) strs. size () & strs [I] = '5'; I ++) ;}else {num = num * 10 + (strs [I]-'0 '); I ++; // details if (I = (int) strs. size () vi. push_back (num); // details} sort (vi. begin (), vi. end (); for (int I = 0; I <(int) vi. size ()-1; I ++) {printf ("% d", vi [I]);} printf ("% d \ n", vi [vi. size ()-1]);} return 0 ;}
     
    
   
  
 



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.