HRusev

Ranges (dynamic memory)

Jun 2nd, 2023
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 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.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     pair<int, int>* range = new pair<int, int>[10000];
  16.     string input;
  17.     int currPos = 0;
  18.     while (true)
  19.     {
  20.  
  21.         getline(cin, input);
  22.         if (input == ".")
  23.             break;
  24.  
  25.         istringstream istr(input);
  26.        // int num;
  27.        // istr >> num;
  28.         istr >> range[currPos].first;
  29.         istr >> range[currPos].second;
  30.         currPos++;
  31.     }
  32.  
  33.     int lastRange = currPos;
  34.    
  35.     while (true)
  36.     {
  37.         currPos = 0;
  38.         getline(cin, input);
  39.         if (input == ".")
  40.             break;
  41.         while (currPos <= lastRange)
  42.         {
  43.             istringstream istr(input);
  44.             int num;
  45.             istr >> num;
  46.             if (range[currPos].first <= num && num <= range[currPos].second)
  47.                 break;
  48.             currPos++;
  49.         }
  50.  
  51.         if(currPos < lastRange)
  52.             cout << "in" << endl;
  53.         else
  54.             cout << "out" << endl;    
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment