EOJ(排序)——2572. Sort it…

2572. Sort it…

There is a database,partychen want you to sort the database’s data in the order from the least up to the greatest element,then do the query: “Which element is i-th by its value?”- with i being a natural number in a range from 1 to N.
It should be able to process quickly queries like this.

输入

The standard input of the problem consists of two parts. At first, a database is written, and then there’s a sequence of queries. The format of database is very simple: in the first line there’s a number N(1⩽N⩽100000), in the next N lines there are numbers of the database one in each line in an arbitrary order. A sequence of queries is written simply as well: in the first line of the sequence a number of queries K(1⩽K⩽100) is written, and in the next K lines there are queries one in each line. The query “Which element is i-th by its value?” is coded by the number i.

输出

The output should consist of K lines. In each line there should be an answer to the corresponding query. The answer to the query “i” is an element from the database, which is i-th by its value (in the order from the least up to the greatest element).
样例

input

5
7
121
123
7
121
3
3
2
5

output

121
7
123

题目大意:

排序+查询。

题目解析:

sort函数排序。

具体代码:

#include<iostream>
#include<algorithm>
using namespace std;
int A[100010];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    	cin>>A[i];
    sort(A,A+n);
    int k;
    cin>>k;
    while(k--){
    	int q;
    	cin>>q;
    	cout<<A[q-1]<<endl;
	}
    return 0;
}
全部评论

相关推荐

菜菜咪:1. 可以使用简历网站的模版,美观度会更好一点 2. 邮箱可以重新申请一个,或者用qq邮箱的别名,部分hr可能会不喜欢数字邮箱 3. 项目经历最好分点描述,类似的项目很多,可以参考一下别人怎么写的 4. 自我评价可加可不加,技术岗更看重技术。最后,加油,优秀士兵
点赞 评论 收藏
分享
12-06 10:46
已编辑
上海大学 C#工程师
LHight:兄弟去偷配方回来
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务