属于sort和lower_bound的初步应用,后者来实现有序数组里面的二分非常方便
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pa;
int main() {
int n, q;
int op = 1;
while (cin >> n >> q) {
if (!n && !q) break;
printf("CASE# %d:\n", op++);
int a[10005];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
while (q--) {
int x;
cin >> x;
int t = lower_bound(a, a + n, x) - a;
if (t == n) printf("%d not found\n", x);
else if (a[t] == x) printf("%d found at %d\n", x, t + 1);
else printf("%d not found\n", x);
}
}
return 0;
}