题解 | #查找#

查找

https://www.nowcoder.com/practice/8e0c0e8c78944847be9bca54b59d713f

#include<bits/stdc++.h>
using namespace std;
int main() {
    set<int>s;
    int n, m;
    cin >> n >> m;
	int a;
	int i=1;
	while(i<=n&&cin>>a)
	{
		s.insert(a);
		i=i+1;
	}
    int x;
    while (m != 0) {
        m--;
        cin >> x;
        set<int>::iterator it1;
        it1 = s.upper_bound(x);
        if (it1 == s.end()) {
            cout << "-1" << endl;
        } else
            cout << *it1 << endl;
    }
    return 0;
}

全部评论

相关推荐

爱吃烤肠的牛油最喜欢...:50K是ssp了估计,ssp的人家多厉害都不用说,每年比例大概在百分之5左右
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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