Vjudge题目链接,sort,lower_bound,STL题,和书上写的一样
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 10010;
int main(){
int n, q, cnt = 1, a[maxn];
while(~scanf("%d %d", &n, &q) && n!=0 && q!=0){
printf("CASE# %d:\n", cnt++);
for(int i = 0; i < n; i++)scanf("%d", &a[i]);
sort(a, a+n);
for(int i = 0; i < q; i++){
int r;
scanf("%d", &r);
int pos = lower_bound(a, a+n, r) - a;
if(a[pos] == r) printf("%d found at %d\n", r, pos+1);
else printf("%d not found\n", r);
}
}
return 0;
}