inhuman_Arif

Playboy chimp

Jan 23rd, 2021
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. using namespace std;
  8. typedef long long ll;
  9.  
  10. int main()
  11. {
  12.     int ch,query;
  13.     map <int, int> mp;
  14.     cin >> ch;
  15.     ll girl, boy;
  16.     vector <ll> chimp;
  17.     for(int i=0;i<ch;i++)
  18.     {
  19.         cin >> girl;
  20.         if(mp.find(girl)!=mp.end())
  21.             continue;
  22.         else
  23.         {
  24.             chimp.push_back(girl);
  25.             mp[girl]=1;
  26.         }
  27.     }
  28.     cin >> query;
  29.     ll luchu[query];
  30.     for(int i=0;i<query;i++)
  31.         cin >> luchu[i];
  32.  
  33.     for(int i=0;i<query;i++)
  34.     {
  35.         int left,right;
  36.         if(luchu[i]<chimp[0])
  37.         {
  38.             cout << "X " << chimp[0] << endl;
  39.             continue;
  40.         }
  41.         else if(luchu[i]==chimp[0])
  42.         {
  43.             cout << "X " << chimp[1] << endl;
  44.             continue;
  45.         }
  46.         else if(luchu[i]>chimp[chimp.size()-1])
  47.         {
  48.             cout << chimp[chimp.size()-1]  << " X" << endl;
  49.             continue;
  50.         }
  51.         else if(luchu[i]==chimp[chimp.size()-1])
  52.         {
  53.             cout << chimp[chimp.size()-2]  << " X" << endl;
  54.             continue;
  55.         }
  56.         else
  57.         {
  58.             for(int j=0;j<chimp.size();j++)
  59.             {
  60.                 if(chimp[j]<luchu[i])
  61.                     continue;
  62.                 else
  63.                 {
  64.                     if(chimp[j]==luchu[i])
  65.                     {
  66.                         if(j+1 <= chimp.size()-1)
  67.                             cout << chimp[j-1] << " " << chimp[j+1] << endl;
  68.                         else
  69.                             cout << chimp[j-1] << " X" << endl;
  70.                         break;
  71.                     }
  72.                     else if(chimp[j]>luchu[i])
  73.                     {
  74.                         cout << chimp[j-1] << " " << chimp[j] << endl;
  75.                         break;
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.     }
  81.     return 0;
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment