About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

রবিবার, ১৫ মার্চ, ২০১৫

UVA solution: 10611 - The Playboy Chimp

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ary[50005],temp[50005],q;
    int n;
    scanf("%d",&n);

    for(int i=0; i<n; i++)scanf("%d",&ary[i]);
    int len=0;

    for(int i=0; i<n; i++)
    {
        if(i==0) temp[len++]=ary[i];

        else
        {
            if (ary[i]!=ary[i-1])  temp[len++]=ary[i];
        }

    }
    cin>>q;
   //for(int i=0; i<len; i++) cout<<temp[i]<<endl;
    for(int i=0; i<q; i++)
    {
        int target;
        scanf("%d",&target);
        if(target<temp[0])
        {
            printf("X %d\n",temp[0]);
            continue;
        }
        if(target==temp[0])
        {
            printf("X %d\n",temp[1]);
            continue;
        }
        if(target==temp[len-1])
        {
            printf("%d X\n",temp[len-2]);
            continue;
        }
        if(target>temp[len-1])
        {
            printf("%d X\n",temp[len-1]);
            continue;
        }
        int low=0,high=len-1,mid;

        while(high-low!=1)
        {
            mid=(low+high)/2;

            if(target==temp[mid])
            {

                low=mid-1;
                high=mid+1;
                break;
            }
            else if(target>temp[mid])low=mid;
            else high=mid;

        }
        printf("%d %d\n",temp[low],temp[high]);

    }





    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন