zoukankan      html  css  js  c++  java
  • HDU_2673 shǎ崽 OrOrOrOrz

      水题,但是要细心

    #include <stdio.h>
    #include
    <stdlib.h>
    #define N 10007
    int a[N], b[N];
    int cmp(const void * a, const void * b)
    {
    return *(int *)a - *(int *)b;
    }
    int main()
    {
    int n, i;
    while(scanf("%d", &n) != EOF)
    {
    for(i = 0; i < n; i++)
    scanf(
    "%d", &a[i]);
    qsort(a, n,
    sizeof(a[0]), cmp);
    int flag = 1,i = 0, j = n-1, k = 1;
    while(i <= j)
    {
    if(flag)
    {
    b[k
    ++] = a[j--];
    flag
    = 0;
    }
    else
    {
    b[k
    ++] = a[i++];
    flag
    = 1;
    }
    }
    for(i = 1; i < k-1; i++)
    printf(
    "%d ", b[i]);
    printf(
    "%d\n", b[k-1]);
    }
    return 0;
    }
  • 相关阅读:
    LeetCode 55
    LeetCode 337
    LeetCode 287
    LeetCode 274
    LeetCode 278
    LeetCode 264
    LeetCode 189
    LeetCode 206
    LeetCode 142
    LeetCode 88
  • 原文地址:https://www.cnblogs.com/vongang/p/2129193.html
Copyright © 2011-2022 走看看