第X大的数
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
X最近爱上了区间查询问题,给出N(N <= 200)个数,然后进行M次询问,每次询问时,输入一个数X(1<= X <= N),输出N个数中第X大的数。
Input
多组输入。
每组首先输入一个整数N,代表有N个数,下面一行包含N个整数,用空格隔开。然后为一个整数M,代表有M次询问,下面的M行,每行一个整数X。
Output
输出N个数中第X大的数。
Example Input
4
1 2 2 3
4
1
2
3
4
Example Output
3
2
2
1
#include <stdio.h>
int main()
{
int i, j, t, n, a[200], m, g;
while(scanf("%d",&n)!=EOF)
{
for(i = 0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i = 0;i<n-1;i++)
{
for(j = i+1;j<n;j++)
{
if(a[i]<a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
scanf("%d", &m);
{
for(i = 0;i<m;i++)
{
scanf("%d",&g);
printf("%d\n",a[g-1]);
}
}
}
return 0;
}