Advertisement
kolioi

04. Ranges C++

Feb 12th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. // Memory: 2.87 MB
  2. // Time: 0.225 s
  3.  
  4. #include <iostream>
  5. #include <vector>
  6. #include <string>
  7. #include <sstream>
  8. #include <algorithm>
  9.  
  10. int main()
  11. {
  12.     using namespace std;
  13.    
  14.     cin.sync_with_stdio(false);
  15.     cout.sync_with_stdio(false);
  16.  
  17.     vector<int> vFrom;
  18.     vector<int> vTo;
  19.  
  20.     string line;
  21.     istringstream iss;
  22.     while (getline(cin, line) && line != ".")
  23.     {
  24.         int from, to;
  25.         iss.clear();
  26.         iss.str(line);
  27.         iss >> from >> to;
  28.         vFrom.push_back(from);
  29.         vTo.push_back(to);
  30.     }
  31.  
  32.     int first = vFrom[0], last = vTo[vTo.size() - 1];
  33.  
  34.     ostringstream os;
  35.     while (getline(cin, line) && line != ".")
  36.     {
  37.         int n;
  38.         iss.clear();
  39.         iss.str(line);
  40.         iss >> n;
  41.  
  42.         if (n < first || n > last)
  43.             os << "out\n";
  44.         else
  45.         {
  46.             auto it = lower_bound(vTo.begin(), vTo.end(), n);
  47.             int index = it - vTo.begin();
  48.             if (n >= vFrom[index] && n <= vTo[index])
  49.                 os << "in\n";
  50.             else
  51.                 os << "out\n";
  52.         }
  53.     }
  54.  
  55.     cout << os.str();
  56.  
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement