zoukankan      html  css  js  c++  java
  • hdu 1106 排序

    这题要注意一下,字符串最后可能不是5的情况,这里容易遗漏!!!

    代码如下:

    #include"stdio.h"
    #include"string.h"
    #include"stdlib.h"

    int num[1000],count;
    char a[1005];

    int cmp(const void *a,const void *b)
    {
     return *(int*)a-*(int*)b;
    }


    void convert(char *a)
    {
     int i,s=0,state=0;
     for(i=0;a[i]!='\0';i++)
     {
      if(a[i]!='5')
      {
       s=s*10+a[i]-'0';
       state=1;
       if(a[i+1]=='\0')
        num[count++]=s;
      }
      else if(state==1&&a[i]=='5')
      {
       num[count++]=s;
       s=state=0;
      }
     }
    }
      

    int main( )
    {
     int i;
     while(~scanf("%s",a))
     {
      count=0;
      convert(a);
      qsort(num,count,sizeof(int),cmp);
      for(i=0;i<count;i++)
      {
       if(i==0)
        printf("%d",num[i]);
       else
        printf(" %d",num[i]);
      }
      printf("\n");
     }
     return 0;
    }

  • 相关阅读:
    ebs R12 支持IE11
    reloc: Permission denied
    3.23考试小记
    3.21考试小记
    3.20考试小记
    3.17考试小记
    3.15考试小记
    3.13考试小记
    3.12考试小记
    3.10考试小记
  • 原文地址:https://www.cnblogs.com/chaosheng/p/2498220.html
Copyright © 2011-2022 走看看