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里也写对了,但在提交的时候总有一点错误,经过几次修改终于做对了。这提醒我在写程序时一定要注意细节,不要范小错误。

  • 相关阅读:
    加密算法
    git 误操作
    element项目发布
    node命令
    计划
    第一次碰见类似留几手的段子手
    【vue】---猫眼项目中使用js组件的时候-------loading 加载 无法移除的原因---------
    【异步】---异步解决方案---
    【问题-方法】---buffer---解决方法,butter 文件转字符串
    【大脑】--如何让大脑快速记忆
  • 原文地址:https://www.cnblogs.com/ttmj865/p/4656481.html
Copyright © 2011-2022 走看看