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 }
  • 相关阅读:
    文科妹子都会用 GitHub,你这个工科生还等什么
    阿里巴巴开发手册强制使用SLF4J作为门面担当的秘密,我搞清楚了
    天啦撸!打印日志竟然只晓得 Log4j?
    老板下了死命令,要把日志系统切换到Logback
    根号x的导数,求导方法
    Java内存模型
    loadrunner截取变量的字符串
    loadrunner11回放日志中文乱码解决办法
    软件性能测试的几个主要术语
    什么是自动化测试框架
  • 原文地址:https://www.cnblogs.com/cpoint/p/3011482.html
Copyright © 2011-2022 走看看