zoukankan      html  css  js  c++  java
  • (HDOJ1040)As Easy As A+B

    Problem Description
    These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
    Give you some integers, your task is to sort these number ascending (升序).
    You should know how easy the problem is now!
    Good luck!
     
    Input
    Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line. 
    It is guarantied that all integers are in the range of 32-int.
     
    Output
    For each case, print the sorting result, and one line one case.
     
    Sample Input
    2
    3 2 1 3
    9 1 4 7 2 5 8 3 6 9
     
    Sample Output
    1 2 3
    1 2 3 4 5 6 7 8 9
     
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<string.h>
     5 
     6 int a[1001];
     7 
     8 int partitions(int a[],int low,int high)
     9 {
    10   int pivotkey=a[low];
    11   while(low<high)
    12   {
    13     while(low<high && a[high]>=pivotkey)
    14     --high;
    15     a[low]=a[high];
    16     while(low<high && a[low]<=pivotkey)
    17     ++low;
    18     a[high]=a[low];
    19   }
    20   a[low]=pivotkey;
    21   return low;
    22 }
    23 
    24 void qsort(int a[],int low,int high)
    25 {
    26   int pivottag;
    27   if(low<high)
    28   { 
    29   pivottag=partitions(a,low,high);
    30   qsort(a,low,pivottag-1);
    31   qsort(a,pivottag+1,high);
    32   }
    33 }
    34 void deal(int a[], int n)
    35 {
    36   int i;
    37   qsort(a,0,n-1);
    38   for(i=0; i<n; i++)
    39   {
    40       if(i>0)
    41         printf(" ");
    42     printf("%d",a[i]);
    43   }
    44   printf("\n");
    45   
    46 }
    47 
    48 void solve()
    49 {
    50   int T,i,n;
    51   while(scanf("%d",&T)!=EOF)
    52   {
    53       while(T--)
    54       {
    55           scanf("%d",&n);
    56           for(i=0; i<n; i++)
    57           {
    58              scanf("%d",&a[i]);
    59           }
    60          deal(a,n);
    61       }
    62   }
    63 }
    64 
    65 int main()
    66 {
    67   solve();
    68   return 0;
    69 }
  • 相关阅读:
    sql2000/2005获取表的列SQL文
    SQL Server未公开的两个存储过程
    HNOI2008 玩具装箱
    noi2004 郁闷的出纳员
    狼抓兔子(平面图转对偶图求最短路)
    pku1917 Automatic Poetry
    幸福的道路
    闲话电子商店(eshop)的设计和经营2
    基金清仓,晚上欢聚
    早上想来想去,把自己的基金卖了1/5
  • 原文地址:https://www.cnblogs.com/cpoint/p/3011482.html
Copyright © 2011-2022 走看看