第X大的数

来源:互联网 发布:软件开发阶段 编辑:程序博客网 时间:2024/04/30 13:07

第X大的数

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

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

41 2 2 341234

Example Output

3221
#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;}

0 0
原创粉丝点击