-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFamilyTreeExpertSystem.cpp
More file actions
62 lines (55 loc) · 1.76 KB
/
Copy pathFamilyTreeExpertSystem.cpp
File metadata and controls
62 lines (55 loc) · 1.76 KB
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
61
62
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
map<string, string> genderExpert;
vector<pair<string, string>> parentsExpert;
void initializeExpert() {
genderExpert["tom"] = "male";
genderExpert["anna"] = "female";
genderExpert["bob"] = "male";
genderExpert["jill"] = "female";
genderExpert["kate"] = "female";
genderExpert["sam"] = "male";
parentsExpert.push_back({"tom", "bob"});
parentsExpert.push_back({"anna", "bob"});
parentsExpert.push_back({"tom", "jill"});
parentsExpert.push_back({"anna", "jill"});
parentsExpert.push_back({"bob", "kate"});
parentsExpert.push_back({"jill", "sam"});
}
bool parentExpert(const string& a, const string& b) {
return any_of(parentsExpert.begin(), parentsExpert.end(), [&](const auto& p) {
return p.first == a && p.second == b;
});
}
bool siblingExpert(const string& a, const string& b) {
if (a == b) return false;
return any_of(parentsExpert.begin(), parentsExpert.end(), [&](const auto& p) {
return parentExpert(p.first, a) && parentExpert(p.first, b);
});
}
bool uncleOrAunt(const string& x, const string& y) {
return any_of(parentsExpert.begin(), parentsExpert.end(), [&](const auto& p) {
return parentExpert(p.first, y) && siblingExpert(x, p.first);
});
}
int main() {
initializeExpert();
cout << boolalpha;
cout << "Is Tom uncle/aunt of Kate? " << uncleOrAunt("tom", "kate") << '\n';
cout << "Is Anna uncle/aunt of Sam? " << uncleOrAunt("anna", "sam") << '\n';
return 0;
}