c++ - Make interval using two set<int> -


we want use 2 set<int>s' create integer-intervals.

some of works want remove interval in our intervals, set sorted! , interval_first[i] != set1[i] , interval_last[i] != set2[i].

as way, how can delete inteval using set<int> st1, nd2 , iterator it1, it2 ?

sample input:

a 2 5

a 3 4

d 2 5

p

result:

1, 2

5, 5

i have code now, , delete not work (because set sorted), please me complete this:

#include <iostream> #include <set> using namespace std;  int main() {     set<int> st1, nd2;     while(true)     {         char order;         cin >> order;         int a, b;         switch(order)         {         //add:         case 'a':             cin >> >> b;             st1.insert(a);             nd2.insert(b);             break;         //delete:         case 'd':             cin >> >> b;             if(st1.find(a) != st1.end() && nd2.find(b) != nd2.end())             {                 st1.erase(a);                 nd2.erase(b);             }             break;         //print:         case 'p':         {             set<int>::iterator it1, it2;             for(it1 = st1.begin(), it2 = nd2.begin(); it1!=st1.end(); it1++, it2++)                 cout << *it1 << ", " << *it2 << endl;             cout << endl;             break;         }         default:             return 0;         }     } } 

note: nd2 means second , st1 means first!


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -