uva-10474 - Where is the Marble?


/*
    Coder: Shawn_Xue
    Date: 2015.4.4
    Result: AC
*/
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int maxn = 10000;
int main()
{
    int n, q, x, a[maxn], kase = 0;
    while(cin >> n >> q && n)
    {
        printf("CASE# %d:\n", ++kase);
        for(int i = 0; i < n; i ++)
        {
            cin >> a[i];
        }
        sort(a, a+n);
        while(q--)
        {
            cin >> x;
            int p = lower_bound(a, a+n, x) - a;//   寻找大于或等于x 的第一个位置
            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?)