Advertisement
Spocoman

02. Ranges

Feb 1st, 2024
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     string line;
  10.     getline(cin, line);
  11.  
  12.     map<int, int> starts;
  13.     map<int, int> ends;
  14.  
  15.     int from, to;
  16.  
  17.     for (int i = 1; line != "."; i++) {
  18.         istringstream ss(line);
  19.  
  20.         ss >> from;
  21.         starts.insert({ from, i });
  22.  
  23.         ss >> to;
  24.         ends.insert({ to, i });
  25.  
  26.         getline(cin, line);
  27.     }
  28.  
  29.     getline(cin, line);
  30.  
  31.     while (line != ".") {
  32.         auto start = starts.upper_bound(stoi(line));
  33.         auto end = ends.lower_bound(stoi(line));
  34.         bool isRange = start != starts.begin() && ((--start)->second == end->second);
  35.  
  36.         cout << (isRange ? "in" : "out") << endl;
  37.  
  38.         getline(cin, line);
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement