Sunday, August 13, 2017

UVa problem 10611 - The Playboy Chimp

problem link:


Discuss: just simply handle query. no tricky part in this problem.

try yourself before see the code


#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n,i,j,q,tall,shot,fin;
    vector<int>vec;
    vector<int>qur;
    cin >>n;
    for(i=0;i<n;i++)
    {
        cin >>j;
        vec.push_back(j);
    }
    sort(vec.begin(),vec.end());
    cin >>q;
    for(i=0;i<q;i++)
    {
        cin >>fin;
        qur.push_back(fin);
    }
    for(i=0;i<q;i++)
    {
        int fs=0,ft=0;
        tall=vec[n-1];
        for(j=0;j<n;j++)
        {
           if(vec[j]<qur[i])
           {
                   shot=vec[j];
                   fs=1;
           }
               if(vec[j]>qur[i])
               {
                   if(vec[j]<=tall)
                   {
                       tall=vec[j];
                       ft=1;
                   }

               }

        }
        if(fs)
            cout <<shot<<' ';
        else
            cout <<'X'<<' ';
        if(ft)
            cout <<tall<<endl;
        else
            cout <<'X'<<endl;
    }

    return 0;
}

No comments:

Post a Comment