hdu1106 sort (split string)

Source: Internet
Author: User

SortTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 41253 Accepted Submission (s): 11824


Problem description Enter a line of numbers, if we take this line of the number of ' 5 ' as a space, then we get a line with a space separated by a number of non-negative integers (some integers may start with ' 0 ', these headers ' 0 ' should be ignored, unless the integer is a number of ' 0 ', then this integer is 0).

Your task is to sort the output from small to large for these segmented integers.


Input inputs contain multiple sets of test cases, each set of input data with only one row of numbers (no spaces between the numbers), and the length of the line number is not greater than 1000.

Input data Assurance: The resulting non-negative integers are not greater than 100000000, and the input data cannot be composed of ' 5 '.

Output for each test case, the result of an integer ordering of the outputs is divided by a single space between the adjacent two integers, one row for each set of outputs.

Sample Input
0051231232050775

Sample Output
0 77 12312320

Sourcepoj
Recommendeddy | We have carefully selected several similar problems for YOU:1108 1201 1040 1280 1236

#include <stdio.h> #include <queue> #include <string.h>using namespace Std;int main () {    priority_ Queue<long long,vector<long long >,greater<long long> > s;    Char str[1005];    int Len,flag;    a long long sum;    while (scanf ("%s", str)!=eof)    {        Len=strlen (str), sum=flag=0;        for (int i=0;i<len;i++)        {                        if (str[i]!= ' 5 ')            sum=sum*10+str[i]-' 0 ', flag=1;            if (str[i]== ' 5 ' | | i==len-1) &&flag)            s.push (sum), sum=flag=0;            }        if (!s.empty ())        printf ("%lld", S.top ()), S.pop ();        while (!s.empty ())        printf ("%lld", S.top ()), S.pop ();        printf ("\ n");        memset (str,0,sizeof (str));    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1106 sort (split string)

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.