Hangzhou Electric OJ 1106

Source: Internet
Author: User

Sort

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 74104 Accepted Submission (s): 22754


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 Input0051231232050775

Sample Output0 77 12312320 This is the first question I brush the Hangzhou electric OJ, I began to use C + +, and then there are a lot of trickery place, the result is WA, I almost thought that is Hangzhou electric does not support vector these libraries, but in fact, people are supported, I forgot to rule out the middle of a continuous 5 of the situation, the harm I was solved in two ways, but the idea of the two methods is the same, the use of something different, here is my code, because I am lazy, the code is the same idea, just write a comment.
#include <iostream>#include<cstdio>#include<algorithm>#include<string>#include<vector>using namespacestd;intMain () {stringA//A is the input string     while(cin>>a) {Vector<Long>b;//b is used to save the integer that is split.         stringC//c is a temporary variable that is used to hold the integer in the split.        intJ;  for(j=0; a[j]=='5'; j + +);//exclude the beginning of the continuous ' 5 '         for(intI=j;i<a.length (); i++){            if(a[i]!='5') c+=A[i]; Else if(a[i-1]!='5'){//if it is a continuous 5, the extra number is not saved. B.push_back (Atol (C.c_str ())); C=""; }        }        if(A[a.length ()-1]!='5')//If the end is not ' 5 ', you also need to save the last segmented integerB.push_back (Atol (C.c_str ())); Sort (B.begin (), B.end ());//Sortcout<<b[0];  for(intI=1; I<b.size (); i++) {cout<<" "<<B[i]; } cout<<"\ n"; }} 

#include <iostream>#include<cstdio>#include<algorithm>#include<string>using namespacestd;intMain () {Chara[1001] ; Longb[ +]; intk=0;  while(SCANF ("%s", a)! =EOF) {        Longs=0; intJ;  for(j=0; a[j]=='5'; j + +); inti;  for(i=j;a[i]!=' /'; i++){            if(a[i]!='5') {s=s*Ten+a[i]-'0'; }            Else if(a[i-1]!='5') {b[k++]=s; S=0; }        }        if(a[--i]!='5') B[k++]=s; S=0; Sort (b,b+k);  for(intI=0; i<k;i++){            if(i==0) cout<<B[i]; Elsecout<<" "<<B[i]; } cout<<"\ n"; K=0; }} 

Hangzhou Electric OJ 1106

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.