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 }
  • 相关阅读:
    Netty入门
    个人网站一步一步搭建——(20)成功在本地IIS运行
    个人网站一步一步搭建——(19)开始为博客园页面绑定数据
    不得了的try catch
    个人网站一步一步搭建——(18)后台整合
    sql拆分列 时间拆分 日、月、年
    个人网站一步一步搭建——(17)简历模块
    个人网站一步一步搭建——(16)发布动态
    MVC将Base64 保存为图片
    JS图片多个上传,并压缩为Base64
  • 原文地址:https://www.cnblogs.com/cpoint/p/3011482.html
Copyright © 2011-2022 走看看