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;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-19 14:46
和女友两个人马上毕业,现在我在鹅实习995,周六日偶尔也去北京;她在北京金融007,经常忙到后半夜,周末也没啥休息机会两个人现在都不咋聊天了,一句话隔半小时甚至半天才回。&nbsp;她是个很优秀的妹子,工作也很努力,是值得学习一辈子的人。我在努力工作求转正,即便不行至少赚到了一段不错的实习经历。已经异地了半年,接下来可能还会持续是这个状态。我们都算是对方重要的人,只是感觉看上去不是很有未来的样子。希望牛友们给点的鼓励
梦旅奇缘:很难。异地首先就已经很难了,加上妹子是金融行业,忙碌高压,对情感需求很高,而且见惯纸醉金迷,你的很多优势在她那里可能就不算什么了。这种情况下,在她们那里遇到一个能及时照顾她的人,即使那人可能很多条件不如你,你也有可能被分手。 说白了,两个卷王就不太适合在一起。因为卷王最大的优势,在另一个卷王那里就不算优势了。
点赞 评论 收藏
分享
面试了几家,全程问项目,八股一点都不问,可惜准备了这么久
独角仙梦境:现在感觉问八股像是中场休息一样的,问几个八股放松一下再上强度
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务