C++ 与STL 入门之一:
1.lower_bound(a, a+n, x);
练习题 Where is the Marble?
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a[10000];
int x, n, m, k = 0;
while (cin >> n >> m) {
k++;
if (n == 0 && m == 0) break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a+n);
cout << "CASE# " << k << ":" << endl;
while (m--) {
cin >> x;
int p = lower_bound(a, a+n, x)-a;
if (a[p] == x) {
cout << x << " found at " << p+1 << endl;
}
else {
cout << x << " not found"<< endl;
}
}
}
}
2. set
练习题 安迪的第一个字典 Andy's First Dictionary
#include<b