###### HDOJ 1040 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
#include <stdio.h>

int num[1002];
int Partition(int left, int right)
{
int x = num[left], t = 0;
while(left<right)
{
while(num[right]>=x && left<right) right--;
t = num[right];
num[right] = num[left];
num[left] = t;
while(num[left]<=x && left<right) left++;
t = num[right];
num[right] = num[left];
num[left] = t;
}
return right;
}
void q_sort(int left, int right)
{
int min = 0;
if(left >= right)
return;
else
{
min = Partition(left, right);
q_sort(left, min-1);
q_sort(min+1, right);
}
}

int main()
{
int i = 0, t = 0, n = 0;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i = 0; i<n; i++)
{
scanf("%d",&num[i]);
}
q_sort(0, n-1);
for(i = 0; i<n-1; i++)
printf("%d ",num[i]);
printf("%d",num[n-1]);
printf("\n");
}
return 0;
}

#### hdoj-1040-As Easy As A+B

2016-06-02 20:15:41

#### HDU-1040-As Easy As A+B(诚如题目所说和A+B一样简单-插入排序水过)

2015-06-09 13:32:20

#### HDOJ 1040 As Easy As A+B

2014-07-21 08:46:35

#### 杭电ACM 1040 As Easy As A+B java 解读

2015-11-02 18:47:39

#### hdoj 1040 As Easy As A+B

2014-07-28 00:07:28

#### HDOJ 1040 As Easy As A+B

2014-07-22 21:13:57

#### HDOJ 1040 As Easy As A+B

2016-02-06 13:56:50

#### HDOJ 1040 As Easy As A+B

2014-02-14 17:39:52

#### Hdoj 1040 As Easy As A+B

2018-02-08 10:20:14

#### hdoj 1040 As Easy As A+B 【归并排序】

2015-10-15 22:25:30

## 不良信息举报

HDOJ 1040 As Easy As A+B 快排