# 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 快排 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)