HRusev

Ranges (vector)

Jun 2nd, 2023
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | Source Code | 0 0
  1. // 02. Ranges.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5. #include<string>
  6. #include <sstream>
  7. #include <set>
  8. #include <algorithm>
  9. #include <queue>
  10. #include <vector>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.  
  17.     vector<pair<int, int>> range;
  18.     //pair<int, int>* range = new pair<int, int>[10000];
  19.     string input;
  20.     int currPos = 0;
  21.     while (true)
  22.     {
  23.         pair <int, int> member;
  24.         getline(cin, input);
  25.         if (input == ".")
  26.             break;
  27.  
  28.         istringstream istr(input);
  29.         // int num;
  30.         // istr >> num;
  31.  
  32.         istr >> member.first;
  33.         istr >> member.second;
  34.         range.push_back(member);
  35.         currPos++;
  36.     }
  37.  
  38.     int lastRange = currPos;
  39.  
  40.     while (true)
  41.     {
  42.         currPos = 0;
  43.         getline(cin, input);
  44.         if (input == ".")
  45.             break;
  46.         while (currPos <range.size())
  47.         {
  48.             istringstream istr(input);
  49.             int num;
  50.             istr >> num;
  51.             if (range[currPos].first <= num && num <= range[currPos].second)
  52.                 break;
  53.             currPos++;
  54.         }
  55.  
  56.         if (currPos < lastRange)
  57.             cout << "in" << endl;
  58.         else
  59.             cout << "out" << endl;
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment