Guest User

Untitled

a guest
Dec 29th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <map>
  5.  
  6. void parseInputData(std::map<int, int>& ranges, std::vector<int>& points) {
  7.   std::istringstream input;
  8.   int start, end;
  9.   std::string line;
  10.  
  11.   while (getline(std::cin, line) && line != ".") {
  12.     input.clear();
  13.     input.str(line);
  14.     if (input >> start >> end) {
  15.       ranges.emplace(end, start);
  16.     }
  17.   }
  18.  
  19.   while (getline(std::cin, line) && line != ".") {
  20.     points.push_back(stoi(line));
  21.   }
  22. }
  23.  
  24. int main() {
  25.   std::ostream::sync_with_stdio(false);
  26.   std::istream::sync_with_stdio(false);
  27.   std::cin.tie(nullptr);
  28.  
  29.   std::map<int, int> ranges;
  30.   std::vector<int> points;
  31.  
  32.   parseInputData(ranges, points);
  33.  
  34.   std::ostringstream oss;
  35.   for (int point : points) {
  36.     auto it = ranges.lower_bound(point);
  37.     bool isIn = it != ranges.end() && it->first >= point && it->second <= point;
  38.     oss << (isIn ? "in" : "out") << std::endl;
  39.   }
  40.   std::cout << oss.str();
  41.  
  42.   return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment