Imran2544

[UVa 10611] The Playboy Chimp (Luchu Bandor)

Nov 11th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, q, k;
  7.     cin>>n;
  8.     int a[n];
  9.     for (int i=0; i<n; i++) {
  10.         cin>>a[i];
  11.     }
  12.     cin>>q;
  13.     while (q--) {
  14.         int s=-1, t=-1;
  15.         cin>>k;
  16.         for (int i=0; i<n; i++) {
  17.             if (a[i]<k)
  18.                 s=a[i];
  19.         }
  20.         for (int i=n-1; i>=0; i--) {
  21.             if (a[i]>k)
  22.                 t=a[i];
  23.         }
  24.         if (s==-1)
  25.             printf("X ");
  26.         else
  27.             printf("%d ", s);
  28.         if (t==-1)
  29.             printf("X\n");
  30.         else
  31.             printf("%d\n", t);
  32.     }
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment