zoukankan      html  css  js  c++  java
  • ACM比赛(11462 Age Sort)

    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.
    Input
    There are multiple test cases in the input le. Each case starts with an integer
    n(0<=n<=200000)
    2000000), the
    total number of people. In the next line, there are
    n
    integers indicating the ages. Input is terminated
    with a case where
    n
    = 0. This case should not be processed.
    Output
    For each case, print a line with
    n
    space separated integers. These integers are the ages of that country
    sorted in ascending order.
    Warning:
    Input Data is pretty big (
    
    25 MB) so use faster IO.
    Sample Input
    5
    3 4 2 1 5
    5
    2 3 2 3 1
    0
    Sample Output
    1 2 3 4 5
    1 2 2 3 3

    程序分析:此题的考点是一个数组数据的排序,值得注意的是此题如果自己写一排序函数(选择法、冒泡法、插入法)会比较耗时导致程序通不过,所以我们可以考虑使用sort函数。还有就是可能会有很多会把数组a开在主函数,非常建议大家不要这样,这样也会很耗时。

    程序代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int a[2000000];
    int main( )
    {int i,n ,j,t,k;
    while(scanf("%d",&n)==1&&n)
    {for(i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+i);
    for(i=0;i<n-1;i++)
    printf("%d ",a[i]);
    printf("%d
    ",a[n-1]);
    
    }
    return 0;
    }
    
  • 相关阅读:
    Handler机制来处理子线程去更新UI线程控件
    获得某月份的天数
    listview选中没有效果
    kali或其他系统,虚拟机中不能加载镜像
    tomcat开启多个端口
    kali自定义分辨率
    Redis 安装手册
    bash检查centos服务器运行状态
    关于利用RD client远程电脑,和输入法的一些问题
    centOS下 MYSQL基本操作
  • 原文地址:https://www.cnblogs.com/yilihua/p/4653572.html
Copyright © 2011-2022 走看看