-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.cpp
60 lines (53 loc) · 1.76 KB
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "common.h"
std::map<std::string, int> argcount;
int get_low(int a)
{
int ans = -1;
while (a > 0) {
ans++;
a /= 2;
}
return ans;
}
std::set<std::string> mySetUnion(const std::set<std::string>& s1,
const std::set<std::string>& s2)
{
std::vector<std::string> v(s1.size() + s2.size());
auto it = std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<std::string>(v.begin(), it);
}
std::set<std::string> mySetDifference(const std::set<std::string>& s1,
const std::set<std::string>& s2)
{
std::vector<std::string> v(s1.size());
auto it = std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<std::string>(v.begin(), it);
}
std::set<std::string> mySetIntersect(const std::set<std::string>& s1,
const std::set<std::string>& s2)
{
std::vector<std::string> v(s1.size());
auto it = std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<std::string>(v.begin(), it);
}
std::set<int> mySetUnion(const std::set<int>& s1,
const std::set<int>& s2)
{
std::vector<int> v(s1.size() + s2.size());
auto it = std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<int>(v.begin(), it);
}
std::set<int> mySetDifference(const std::set<int>& s1,
const std::set<int>& s2)
{
std::vector<int> v(s1.size());
auto it = std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<int>(v.begin(), it);
}
std::set<int> mySetIntersect(const std::set<int>& s1,
const std::set<int>& s2)
{
std::vector<int> v(s1.size());
auto it = std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(), v.begin());
return std::set<int>(v.begin(), it);
}