UVA 10474 Where is the Marble?






#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,q,i,j,k,l,m,t=0;
    //freopen("uvain.txt","r",stdin);
    //freopen("uvaout.txt","w",stdout);
    while(cin>>n>>q)
    {
        vector<long long int>v;
        v.clear();
        t++;
        if(n==0 && q==0)
        {
            break;
        }
        for(i=1;i<=n;i++)
        {
            cin>>k;
            v.push_back(k);
        }
        sort(v.begin(),v.end());
        printf("CASE# %lld:\n",t);
        for(i=1;i<=q;i++)
        {
            cin>>l;
            vector<long long int>::iterator low;
            j=binary_search(v.begin(),v.end(),l);
            if(j)
            {
                low=lower_bound(v.begin(),v.end(),l);
                m=(low-v.begin());
                printf("%lld found at %lld\n",l,m+1);
            }
            else
            {
                printf("%lld not found\n",l);
            }


        }
    }

    return 0;
}







Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment