uva 10474 Where is the Marble?

#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
const int M=10000;
int main()
{
    int n,q,x,kase=0;
    while(scanf("%d%d",&n,&q)==2&&n)
    {
        int a[n];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a,a+n);
        cout<<"CASE# "<<++kase<<":"<<endl;
        while(q--)
        {
            scanf("%d",&x);
            int p=lower_bound(a,a+n,x)-a;//关于lower_bround返回值特意百度,弄懂了,用它减去地址就是位置
            if(a[p]==x)
               printf("%d found at %d\n",x,p+1);
            else
                printf("%d not found\n",x);
        }
    }
    return 0;
}

你可能感兴趣的:(uva 10474 Where is the Marble?)