#include<iostream>
#include<algorithm>
#define maxn 10000
using namespace std;
int a[maxn],b[maxn];
int main()
{
int n,q,k=1;
while(cin>>n>>q,n||q)
{
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<q;i++)
cin>>b[i];
sort(a,a+n);
cout<<"CASE# "<<k++<<":"<<endl;
int site;
for(int i=0;i<q;i++)
{
site=-1;
for(int j=0;j<n;j++)
{
if(b[i]==a[j])
{
site=j;
break;
}
}
if(site==-1)
cout<<b[i]<<" not found"<<endl;
else
cout<<b[i]<<" found at "<<site+1<<endl;
}
}
return 0;
}
刘大大的:
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 10000;
int main()
{
int n,q,x,a[maxn],kase=0;
while(scanf("%d%d",&n,&q)==2&&n)
{
printf("CASE# %d:\n",++kase);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
while(q--)
{
scanf("%d",&x);
int p=lower_bound(a,a+n,x)-a;
if(a[p]==x) printf("%d found at %d\n",x,p+1);
else printf("%d not found\n",x);
}
}
return 0;
}