| ||||||||||
| 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 | |||||||||
有比这更水的吗?NO!//上面排个序,下面输出
#include <iostream>
using namespace std;
void Swap(int *a,int i,int j)
{
int x;
x=a[i];a[i]=a[j];a[j]=x;
}
int partition(int p,int r,int *a)
{
int i=p,j=r+1;
int x=a[p];
while(true)
{
while(a[++i]<x&&i<r);
while(a[--j]>x);
if(i>=j)
break;
Swap(a,i,j);
}
a[p]=a[j];
a[j]=x;
return j;
}
void qSort(int p,int r,int *a)
{
if(p<r)
{
int q=partition(p,r,a);
qSort(p,q-1,a);
qSort(q+1,r,a);
}
}
int main()
{
char a[4];
int s[150000],i,n,b[5000];
cin >> n;
for(i=0;i<n;i++)
cin >> s[i];
qSort(0,n-1,s);
cin >> a;
cin >> n;
while(n--)
{
cin >> i;
cout << s[i-1] << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator