Ural 1026 Questions and answers

Ural 1026 Questions and answers
The solution is to sort.Quick sort will be okay.
And pay attention to the string of three symbols "#".
Here is my code:
#include < iostream >
#define  maxn 100007
using   namespace  std;
long  n,k,r[maxn];
void  Qsort( long   * a, long  l, long  r)
{
    
long  i = l,j = r,mid = a[(l + r) / 2 ];
    
do {
        
while (a[i] < mid) i ++ ;
        
while (a[j] > mid) j -- ;
        
if (i <= j)
        {
            
long  t = a[i];a[i] = a[j];a[j] = t;
            i
++ ;j -- ;
        }
    }
while (i <= j);
    
if (l < j) Qsort(a,l,j);
    
if (i < r) Qsort(a,i,r);
}
int  main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    cin
>> n;
    
for ( long  i = 1 ;i <= n;i ++ )
        cin
>> r[i];
    Qsort(r,
1 ,n);
    getchar();getchar();getchar();getchar();getchar();
    cin
>> k;
    
for ( long  i = 1 ;i <= k;i ++ )
    {
        
long  t;
        cin
>> t;
        cout
<< r[t] << endl;
    }
return   0 ;
}


你可能感兴趣的:(Ural 1026 Questions and answers)