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

  • 相关阅读:
    理解C#系列 / 核心C# / 常量
    理解C#系列 / 核心C# / 变量
    理解C#系列 / C#语言的特性
    理解C#系列 / .NET体系结构
    利用DMZ对象保护全局变量
    随手翻的一道摩拜校招题
    关于为函数形参赋值和搜索变量标识符的云云
    竟然修改形参有这么可怕的后果!!
    牛得一逼的delete操作符
    屏蔽属性
  • 原文地址:https://www.cnblogs.com/ttmj865/p/4656481.html
Copyright © 2011-2022 走看看