poj 2371 Questions and answers

题目链接:http://poj.org/problem?id=2371

题意:前面给出N和N个数,中间一串字符串(分割用),后面给出M和M个询问,问第I小的数字是多少。

分析:水。。。直接sort一下,然后输出第I-1个就好(下标从0开始)。

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
#define Max(a,b) (a>b)?a:b
#define lowbit(x) x&(-x)
int n,a[1000005];
int main()
{

    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    char s[105];
    scanf("%s",s);
    int m;
    scanf("%d",&m);
    while(m--)
    {
        scanf("%d",&n);
        printf("%d\n",a[n-1]);
    }
}
View Code

 

posted @ 2016-08-17 19:29  wwdf  阅读(157)  评论(0编辑  收藏  举报