Sort
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 41909 Accepted Submission (s): 12014
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
Source POJ
Recommendeddy | We have carefully selected several similar problems for you:1108 1280 1236 1004 1391 note more than 5, with a tail and a 5, a variety of situations can be. But it's easier to do this with a container, and then stick to someone else's code and learn later
#include <queue>#include<map>#include<math.h>#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespacestd;#defineN 100005intnum,cnt;CharStr[n];CharStr2[n];intA[n];intMain () { while(cin>>str2) {num=cnt=0; intk=0;intflag=1; memset (str,0,sizeof(str)); for(intI=0; str2[i];i++) { if(str2[i]=='5'&&flag)Continue; Str[k++]=str2[i];flag=0; } //cout<<str<<endl; for(intI=0;; i++) { if(str[i]==' /') {a[cnt++]=num; Num=0; Break; } if(str[i]=='5') { if(str[i+1]==' /'|| str[i+1]=='5')Continue; A[cnt++]=num; Num=0; Continue; } num=num*Ten+ (str[i]- -); } sort (A,a+CNT); intJ; for(j=0; j<cnt-1; j + +) printf ("%d", A[j]); printf ("%d\n", A[j]); } return 0;}
#include <iostream>#include<sstream>#include<vector>#include<cstdlib>#include<algorithm>using namespacestd;intMain () {stringstr; while(cin>>str) {Vector<string>v1; Vector<int>v2; for(intI=0; I!=str.size (); + +i) {if(str[i]=='5') Str[i]=' '; } Istringstreaminch(str); stringtemp; while(inch>>temp) V1.push_back (temp); for(Auto B=v1.cbegin (); B!=v1.cend (); + +b) {intTemp=atoi (b->c_str ()); V2.push_back (temp); } sort (V2.begin (), V2.end ()); Auto B=V2.cbegin (); for(; B!=v2.cend ()-1;++b) cout<<*b<<" "; cout<<*b<<Endl; } return 0;}
HDU 1106 Sort