• 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; }
  • 相关阅读:
    Metinfo 5.x 管理员密码重置漏洞
    【CVE-2018-11116】openwrt rpcd 配置文件错误导致访问控制失效
    openwrt-rpcd服务ACL配置错误风险分析
    黑客基础知识
    渗透测试(漏洞利用)
    Niagara物联网框架机制二(笔记)
    基于kali linux无线网络渗透测试
    渗透测试(漏洞扫描)
    Workbench热水泵系统
    Niagara物联网框架机制一(笔记)
  • 原文地址:https://www.cnblogs.com/chenchunhui/p/4654948.html
Copyright © 2020-2023  润新知