| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
麻烦看一下,想了好多测试数据都行,一上去就WA了#include <iostream>
using namespace std;
unsigned long QKSort(unsigned long *array, unsigned long low, unsigned long high)
{ //实现对array的一次快速排序
array[0] = array[low];
while(low < high)
{
while((array[high] > array[0]) && (low < high))
high--;
if(low < high)
array[low++] = array[high];
while((array[low] < array[0]) && (low <high))
low++;
if(low <high)
array[high++] = array[low];
}
array[low] = array[0];
return low;
}//en of QKsort
void QuickSort(unsigned long *array, unsigned long low, unsigned long high)
{
if(low < high)
{
long pos = QKSort(array,low,high);
QuickSort(array,low,pos-1);
QuickSort(array,pos+1,high);
}
}//end of QuickSort
int main()
{
long n, i=0;
scanf("%ld",&n);
unsigned long *sequence = new unsigned long[n+1];
while((++i)<=n)
scanf("%ld",&sequence[i]);
//end of input
QuickSort(sequence,1,n);
if(n%2 == 1)
cout<<sequence[n/2+1]<<endl;
else
cout<<(sequence[n/2]+sequence[n/2+1])/2.0<<endl;
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator