zoukankan      html  css  js  c++  java
  • 数列排序

    1131: 数列排序

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 316  Solved: 100
    [Submit][Status][BBS]

    Description

    将一正整数序列{K1,K2,...,K9}重新排列成一个新的序列。新序列中,比K1小的数都在K1的前面(左面),比K1大的数都在K1的后面(右面)。

    Input

    输入有多行,第一行为N表示行数,每行9个整数.

    Output

    输出N行,按要求进行排序的结果.

    Sample Input

    2
    6 8 9 1 2 5 4 7 3
    3 5 8 9 1 2 6 4 7

    Sample Output

    3 4 5 2 1 6 8 9 7
    2 1 3 5 8 9 6 4 7

    HINT

    Source

    吉首大学软件学院

    我用的方法很笨,还定义了好多变量。。。。。。。

     1 #include <stdio.h>
     2 int main()
     3 {
     4     int n;
     5     scanf("%d",&n);
     6     while(n--)
     7     {
     8         int i,b[10],a[10],c[10];
     9         for(i=0; i<9; i++)
    10         {
    11             scanf("%d",&a[i]);
    12         }
    13         int k=0,m=a[0];
    14         for(int j=1; j<9; j++)
    15         {
    16             if(a[j]<a[0])
    17             {
    18                 b[k++]=a[j];
    19             }
    20         }
    21         for(i=k-1; i>=0; i--)
    22         {
    23             printf("%d ",b[i]);
    24         }
    25         int v=0;
    26         for(int i=0; i<9; i++)
    27         {
    28             if(a[i]>=m)
    29             {
    30                c[v++]=a[i];
    31             }
    32         }
    33         for(i=0; i<v-1; i++)
    34         {
    35             printf("%d ",c[i]);
    36         }
    37         printf("%d
    ",c[v-1]);
    38     }
    39 }
  • 相关阅读:
    设计模式六大原则
    .net Stream篇(七)
    .net Stream篇(六)
    .net Stream篇(五)
    .net Stream篇(四)
    Leetcode 18
    Leetcode 16
    Leetcode 15
    Leetcode 12
    Leetcode 9
  • 原文地址:https://www.cnblogs.com/tianmin123/p/4739776.html
Copyright © 2011-2022 走看看