BNU Questions and answers

http://www.bnuoj.com/bnuoj/problem_show.php?pid=2490

这个题是先输入一个整数n,说明有几个数据,然后输入n个整数,然后用三个#分开,后面输入整数k,代表有k个数据,后面每个数据代表查询前面那几个整数中从小到大排序后的第几个数。

AC代码:
#include<iostream>

#include<cstdio>

#include<algorithm>



using namespace std;



bool cmp(int a, int b)

{

    return a<b;

}



int a[100010];



int main()

{

    int n,i,k;

    char b[3];

    while(scanf("%d",&n)!=EOF)

    {

        for(i = 0; i < n; i++)

        {

            scanf("%d",&a[i]);

        }

        sort(a,a+n,cmp);

        scanf("%s",&b);

        scanf("%d",&k);

        while(k--)

        {

            scanf("%d",&n);

            printf("%d\n",a[n-1]);

        }

    }



    return 0;

}



 

你可能感兴趣的:(IO)