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 }
  • 相关阅读:
    3-05. 寻求倒数第二链线性表K项目(15)(STL list应用 ZJU_PAT)
    springbatch操作CSV文件
    oracle 数据库技术支持生命周期表
    调试经验--硬盘U菜
    hdu149850 years, 50 colors (多个最小顶点覆盖)
    POJ3213(矩阵乘法)
    Cocos2d-x 2.3.3版本 FlappyBird
    POJ 2114 Boatherds 划分树
    jQuery 添加 删除 改动select option
    STL容器存储的内容动态分配情况下的内存管理
  • 原文地址:https://www.cnblogs.com/cpoint/p/3011482.html
Copyright © 2011-2022 走看看