题解 | #查找#
查找
https://www.nowcoder.com/practice/8e0c0e8c78944847be9bca54b59d713f
利用集合自动排序
#include <bits/stdc++.h> #include <algorithm> using namespace std; int main(){ set<int> s; //write your code here...... int m, n; int tmp; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> tmp; s.insert(tmp); } for(int i = 0; i < m; i++){ cin >> tmp; set<int>::iterator itr = s.upper_bound(tmp); if(itr == s.end()) cout << -1 << endl; else cout << *itr << endl; } return 0; }