Run ID:146997
提交时间:2026-02-02 09:19:45
#include <bits/stdc++.h> using namespace std; int main() { string a; int i,j,k,m,n,f,t; while(cin>>a) { n=a.size(); i=0; j=0; char b[500][10],temp[10]; while(i<n) { if(a[i-1]=='5' or i==0) { if(a[i]=='0') { t=i; while(a[t]!='5' and a[t]=='0') a[t++]=' '; } } if(a[i]=='5' and a[i-1]==' ' and i!=0) a[i-1]='0'; else if(i+1==n and a[i]==' ') a[i]='0'; i++; } //cout<<a<<endl; i=0; while(i<n) { f=0; while(true) { if(a[i]!='5' and a[i]!=' ') //55556785555000055 b[j][f++]=a[i]; i++; //if(a[i+1]=='\0') //break; if(a[i]=='5' and a[i+1]!='5') { b[j][f]='\0'; if(b[j][0]!='\0') j++; break; } } i++; } //printf("n=%d\n",j); n=j; i=0; while(i<n) { j=i; while(j<n) { if(strlen(b[j])<strlen(b[i])) { strcpy(temp,b[j]); strcpy(b[j],b[i]); strcpy(b[i],temp); } else if(strlen(b[j])==strlen(b[i]) and strcmp(b[j],b[i])<0) { strcpy(temp,b[j]); strcpy(b[j],b[i]); strcpy(b[i],temp); } j++; } i++; } i=0; while(i<n) printf("%s ",b[i++]); printf("\n"); } return 0; }