• 比赛年龄排序问题解题报告


    年龄排序

    题目大意:

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

  • 相关阅读:
    Test
    Python Requests库使用指南
    Python文件操作,看这篇就足够
    Ubuntu配置完全教程
    Redis入门
    Python Requests 库学习笔记
    c++11函数模板“偏特化”的一种实现
    c++通用判零模板类
    Python实现1-9数组形成的结果为100的所有运算式
    QT:用QWebSocket实现webchannel,实现C++与HTML通信
  • 原文地址:https://www.cnblogs.com/ttmj865/p/4656481.html
Copyright © 2020-2023  润新知