zoukankan      html  css  js  c++  java
  • 2015 HUAS Provincial Select Contest #1~B

    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 file. Each case starts with an integer n (0 < n ≤ 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

    解题思路:首先是以0为结束标志,所以在输入一个数字之后判断是否为0,再继续进行操作。简单说就是一个排序问题,输入一组数据经过排序后输出,但是这里要注意一个时间问题,如果用cin和cout,那么将很容易时间超出,最好用scanf和printf来进行输入和输出操作,这样才能保证时间在规定的时间内。

    程序代码:

    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int maxn=2000000;
     int a[maxn];
    int main()
    {
       int n,p=1;
      
       while(scanf("%d",&n)==1&&n)
    { for(int i=0;i<n;i++) scanf("%d",&a[i]); for(int z=0;z<n;z++) if(a[z]<1||a[z]>=100)  { p=0; break;} else continue; if(p==1)
    {
    sort(a,a+n); for(int x=0;x<n-1;x++) printf("%d ",a[x]);
    printf("%d",a[n-1]);
    printf(" "); } } return 0; }
  • 相关阅读:
    PHP-FPM详解
    Nginx与PHP交互过程 + Nginx与PHP通信的两种方式
    cgi,fast-cgi,php-cgi,php-fpm转载详解
    ( 转 ) mysql复合索引、普通索引总结
    快速搭建ELK日志分析系统
    高并发
    多线程
    关于MySQL中查询大数据量的情况下分页limit的性能优化
    电商搜索引擎的架构设计和性能优化
    MYSQL优化之碎片整理
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4654948.html
Copyright © 2011-2022 走看看