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

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.