Advertisement
CosminVarlan

bac_2020_var17_subIII_pb3

May 13th, 2020
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. // bac_2020_var17_subIII_pb3
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("bac.txt");
  8.  
  9.  
  10. short v[10000];
  11. short n,a,b;
  12.  
  13. short cauta(short a){
  14.     short st = 0, dr = n-1;
  15.     while(st<=dr){
  16.         short mij=(st+dr)/2;
  17.         if (v[mij]==a) return mij;
  18.         if (v[mij]<a) st = mij+1;
  19.         else dr = mij-1;
  20.     }
  21.     return dr;
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     fin >> n;
  28.     for(short i=0; i<n; i++)
  29.         fin >> v[i];
  30.  
  31.     while (fin >> a)
  32.     {
  33.         fin >> b;
  34.         int poz1 = cauta (a);
  35.         if (poz1>=0 && v[poz1]!=a && poz1+1<=n-1 && b<v[poz1+1]) cout << a << ' ' << b << endl;
  36.         if (poz1<0 && b<v[0]) cout << a << ' ' << b << endl;
  37.         if (poz1==n-1 && v[poz1]!=a) cout << a << ' ' << b << endl;
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement