杭电1106
从字符串中找出数字,并排序输出
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 //1106排序 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 int cmp(const void *a,const void *b) 6 { 7 return *(int *)a-*(int *)b; 8 } 9 int main() 10 { 11 int a[1001],i,j,k,l,w; 12 char s1[1001],s2[1001]; 13 while(gets(s1)) 14 { 15 l=strlen(s1); 16 s1[l]='5';j=0;k=0; 17 for(i=0;i<=l;i++) 18 { 19 if(s1[i]!='5') 20 { 21 s2[k++]=s1[i]; 22 23 } 24 if(s1[i]=='5'&&k!=0)//当连着多个5时,s2[k]为空,不用输出,故k!=0 25 { 26 s2[k]='\0'; 27 a[j++]=atoi(s2); 28 k=0; 29 } 30 31 32 } 33 qsort(a,j,sizeof(a[0]),cmp); 34 printf("%d",a[0]); 35 for(i=1;i<j;i++) 36 printf(" %d",a[i]); 37 printf("\n"); 38 39 } 40 return 0; 41 }