排序
Description
Input
Output
Sample Input
0051231232050775
Sample Output
0 77 12312320
#include<iostream> #include<cstring> using namespace std; int adjust(int s[], int l, int r) { int i = l, j = r; int x = s[l]; while(i < j){ while(i < j && s[j] >= x) j--; if(i < j) { s[i] = s[j]; i++; } while(i < j && s[i] < x) i++; if(i < j){ s[j] = s[i]; j--; } } s[i] = x; return i; } void qsort(int s[], int l, int r) { if(l < r){ int i = adjust(s, l, r); qsort(s, l, i-1); qsort(s, i+1, r); } } int main(){ char str[1001]; while(cin>>str){ int i=0, j=0, s[1000]; while(str[i]=='5') i++; for( ; i<strlen(str); ){ s[j] = 0; while(str[i]!='5' && i<strlen(str) ){ s[j] = s[j]*10 + (str[i]-'0'); i++; } j++; while(str[i]=='5') i++; } qsort(s, 0, j-1); for(i=0; i<j; i++) i==0? cout<<s[i] : cout<<" "<<s[i]; cout<<endl; } return 0; }