/*
* POJ_2371.cpp
*
* Created on: 2013年11月1日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100010;
int a[maxn];
int main(){
int n,k;
while(scanf("%d",&n)!=EOF){
int i;
for(i = 1 ; i <= n ; ++i){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n);
char str[maxn];
scanf("%s",&str);
scanf("%d",&k);
for(i = 1 ; i <= k ; ++i){
int b;
scanf("%d",&b);
printf("%d\n",a[b]);
}
}
return 0;
}
(使用STL自带的排序函数7.3.4)POJ 2371 Questions and answers(sort()函数的使用)
本文提供了一段解决POJ_2371问题的C++代码实现,该程序首先读取整数数量n及n个整数,并对其进行排序。随后读取一串字符并忽略之,接着读取整数k,最后读取k个索引值并输出相应位置的整数值。这段代码适用于解决简单的输入输出及排序问题。

被折叠的 条评论
为什么被折叠?



