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

    http://acm.hdu.edu.cn/showproblem.php?pid=1106

    比较简单,不过还是出错了、

    输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。

    你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int cmp(const void *a,const void *b)
    {
        return (*(int*)a)-(*(int*)b);
    }
    int main()
    {    char c;
      int n,i,k,flag;
      int a[1000];
      while(scanf("%c",&c)!=EOF)
      {
          flag=k=n=0;
          if(c!='5')
           {n=n*10+c-'0';flag=1;}
          while(scanf("%c",&c),c!='\n')
          {
              if(c!='5')
              {
                n=n*10+c-'0';flag=1;
              }
              else if(flag==1)
                 {
                     a[k++]=n;
                      n=0;
                    flag=0;
                 }
          }
          if(flag==1)
            a[k++]=n;
          qsort(a,k,sizeof(a[0]),cmp);
          for(i=0;i<k-1;i++)
            printf("%d ",a[i]);
          printf("%d\n",a[i]);
      }

      return 0;
    }

  • 相关阅读:
    UVALive 7141 BombX
    CodeForces 722D Generating Sets
    CodeForces 722C Destroying Array
    CodeForces 721D Maxim and Array
    CodeForces 721C Journey
    CodeForces 415D Mashmokh and ACM
    CodeForces 718C Sasha and Array
    CodeForces 635C XOR Equation
    CodeForces 631D Messenger
    田忌赛马问题
  • 原文地址:https://www.cnblogs.com/372465774y/p/2427627.html
Copyright © 2011-2022 走看看