zoukankan      html  css  js  c++  java
  • 比赛年龄排序问题解题报告

    年龄排序

    题目大意:

    You are given the ages (in years) of all people of a country with at least 1 year of age. You know that
    no individual in that country lives for 100 or more years. Now, you are given a very simple task of
    sorting all the ages in ascending order.

    要求:

    输入:

    输入文件要测试案例。输入整数n(0 < n ≤ 2000000),下一行有n个年龄。当输入0时 ,输入终止,案例没有被处理。

    输出:

    输出的每个数之间有一个空格,国家的年龄按升序排序。

    警告:
     Input Data is pretty big (∼ 25 MB) so use faster IO. 

    题目分析:

    使用sort 函数进行升序排序,注意sort函数的头文件是<algorithm>.

    程序代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 using namespace std;
     5 
     6 const int maxn=20000000;
     7 int n[2000000];
     8 int a[maxn];                        //大数组要定义在外面
     9 
    10 int main ()
    11 {
    12     int n,i;
    13     while(scanf("%d",&n)==1&&n)
    14     {
    15         for(i=0;i<n;i++)
    16             scanf("%d",&a[i]);
    17         getchar();                  //吸收最后一个空格
    18         sort(a,a+n);                //按升序排序
    19         for(i=0;i<n-1;i++)
    20             printf("%d ",a[i]);
    21         printf("%d",a[n-1]);
    22 
    23         printf("\n");
    24     }
    25     return 0;
    26 }

    心得:

    这道题做了好久,其实题目不是很难,在VC里也写对了,但在提交的时候总有一点错误,经过几次修改终于做对了。这提醒我在写程序时一定要注意细节,不要范小错误。

  • 相关阅读:
    autocomplete="off" 不起作用
    IE8兼容模式设置
    H5学习
    wampserver安装配置
    HTML5音乐播放器(最新升级改造加强版)
    HTML5+CSS3+jquery实现简单的音乐播放器
    jquery+css3实现3d滚动旋转
    HTML5游戏设计与开发 小白7-9月的动态
    jquery submit()不执行
    html5手机常见问题与工具分享
  • 原文地址:https://www.cnblogs.com/ttmj865/p/4656481.html
Copyright © 2011-2022 走看看