UVA 10474 Where is the Marble? Solution

Solution in C++:

///**********ALLAH IS ALMIGHTY************///

///AH Tonmoy

///Department of CSE,23rd batch

///Islamic University,Bangladesh

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int i,n,q,a,b,t,fn;

    for(t=1; t<=65; t++)

    {

        cin>>n>>q;

        if(n==0&&q==0)

            break;

        vector<int>an;

        vector<int>aq;

        for(i=0; i<n; i++)

        {

            cin>>a;

            an.push_back(a);

        }

        sort(an.begin(),an.end());

        for(i=0; i<q; i++)

        {

            cin>>b;

            aq.push_back(b);

        }

        printf("CASE# %d:\n",t);

        for(i=0; i<q; i++)

        {

            bool r=binary_search(an.begin(),an.end(),aq[i]);

            if(r==true)

            {

                int pos;

                pos=lower_bound(an.begin(),an.end(),aq[i])-an.begin();

                printf("%d found at %d\n",aq[i],pos+1);

            }

            else

                printf("%d not found\n",aq[i]);

        }

    }

}


No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.