题意

  给你最多2000000个数据,大小是1到99的数,让你排序输出。

分析

  快排也可以过。不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看清范围,我看成1到100了TAT)有几个就输出几次。这题还有注意格式,最后不要空格,然后换行。

代码

#include<cstdio>
#include<cstring>
int n,a[100],age,ok;

int main()
{
    while(scanf("%d",&n)&&n)
    {
        memset(a,0,sizeof(a));
        ok=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&age);
            a[age]++;
        }
        for(int i=1; i<100; i++)
        {
            for(int j=1; j<=a[i]; j++)
                if(ok)printf(" %d",i);
                else
                {
                    printf("%d",i);
                    ok=1;
                }
        }
        printf("\n");
    }
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-07-21
  • 2021-12-12
  • 2021-08-15
  • 2021-11-06
  • 2021-05-30
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-11-21
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案