zoukankan      html  css  js  c++  java
  • GDUEFE ACM1003 练手

    排序

    Special Judge

    Time Limit: 2000/1000ms (Java/Others) 64bit IO Format: %lld & %llu

    Problem Description:

      给一个不重复的数组,将他排序成a1>a2<a3>a4<a5>a6..这样,结果不唯一

    Input:

    输入多组数据,每组数据第一行一个n,接下来第二行有n个数。

    Output:

    输出满足要求的序列。

    Sample Input:

    5
    1 2 3 4 5
    6
    1 2 3 4 5 6

    Sample Output:

    2 1 5 3 4
    2 1 5 3 6 4

    排序

    Special Judge

    Time Limit: 2000/1000ms (Java/Others) 64bit IO Format: %lld & %llu

    Problem Description:

      给一个不重复的数组,将他排序成a1>a2<a3>a4<a5>a6..这样,结果不唯一

    Input:

    输入多组数据,每组数据第一行一个n,接下来第二行有n个数。

    Output:

    输出满足要求的序列。

    Sample Input:

    5
    1 2 3 4 5
    6
    1 2 3 4 5 6

    Sample Output:

    2 1 5 3 4
    2 1 5 3 6 4
    头脑短路了,WA了很多次才AC,注意一下输出那里,不要有多余空格。
    AC代码:
     1 #include<stdio.h>
     2 int main()
     3 {
     4     int a[100],b,c;
     5     int n,i,j;
     6     while(scanf("%d",&n)!=EOF)
     7     {
     8         for(i=0;i<n;i++)
     9         {
    10             scanf("%d",&a[i]);
    11         }
    12         for(j=0;j<n;j++)
    13         {
    14             for(i=0;i<n;i=i+2)
    15             {
    16                 if(a[i]<a[i+1])
    17                 {
    18                     b=a[i];
    19                     a[i]=a[i+1];
    20                     a[i+1]=b;
    21                 }
    22                 if(i-1<0)
    23                     continue;
    24                 if(a[i]<a[i-1])
    25                 {
    26                     c=a[i];
    27                     a[i]=a[i-1];
    28                     a[i-1]=c;
    29                 }
    30             }
    31         }
    32         printf("%d",a[0]);
    33         for(i=1;i<n;i++)
    34         {
    35             printf(" ");
    36             printf("%d",a[i]);
    37         }
    38         printf("\n");
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    每天一个linux命令(22):find 命令的参数详解
    在gitlab中创建项目后如何用git初始上传项目
    TensorBoard可视化
    docker CMD 和 ENTRYPOINT 区别
    django 项目开发及部署遇到的坑
    nginx + uwsgi 部署django项目
    centos7 追加python3 + 使用pip + virtualenv
    docker 常用命令
    Django+celery+rabbitmq实现邮件发送
    web框架链接
  • 原文地址:https://www.cnblogs.com/2119662736lzj/p/6075430.html
Copyright © 2011-2022 走看看