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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.