Created
February 8, 2019 12:35
-
-
Save dlbas/c1bda62bd26574628384d22a1891ad22 to your computer and use it in GitHub Desktop.
stl lab 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <set> | |
| #include <vector> | |
| #include <stdio.h> | |
| #include <utility> | |
| #include <numeric> | |
| #include <algorithm> | |
| using namespace std; | |
| vector<int> operation1(set<int> a, set<int> b, set<int> superset) { | |
| vector<int> v; | |
| set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(v)); | |
| set<int> middle_set(v.begin(), v.end()); | |
| vector<int> result; | |
| set_difference(superset.begin(), superset.end(), middle_set.begin(), middle_set.end(), back_inserter(result)); | |
| return result; | |
| } | |
| vector<int> operation2(set<int> a, set<int> b, set<int> superset) { | |
| vector<int> not_a; | |
| set_difference(superset.begin(), superset.end(), a.begin(), a.end(), back_inserter(not_a)); | |
| vector<int> not_b; | |
| set_difference(superset.begin(), superset.end(), b.begin(), b.end(), back_inserter(not_b)); | |
| vector<int> result; | |
| set_intersection(not_a.begin(), not_a.end(), not_b.begin(), not_b.end(), back_inserter(result)); | |
| return result; | |
| } | |
| int main() { | |
| int n = 200; | |
| vector<int> v(n); | |
| iota(v.begin(), v.end(), 0); | |
| set<int> U(v.begin(), v.end()); | |
| set<int> A; | |
| int i = 0; | |
| for (auto it: U) { | |
| if (i++ < 100) A.insert(it); | |
| else break; | |
| } | |
| set<int> B; | |
| for (auto it: U) { | |
| if (it % 2 != 0) B.insert(it); | |
| } | |
| vector<int> op1_result = operation1(A, B, U); | |
| // cout << op1_result.size() << endl; | |
| for (auto it: op1_result) { | |
| cout << it << " "; | |
| } | |
| cout << "------" << endl; | |
| vector<int> op2_result = operation2(A, B, U); | |
| // cout << op2_result.size() << endl; | |
| for (auto it: op2_result) { | |
| cout << it << " "; | |
| } | |
| cout << "------" << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment