-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleClassificationProlog.cpp
More file actions
51 lines (46 loc) · 1.4 KB
/
Copy pathVehicleClassificationProlog.cpp
File metadata and controls
51 lines (46 loc) · 1.4 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
#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;
struct Vehicle {
string name;
set<string> attrs;
};
string classifyVehicle(const Vehicle& v) {
const set<string> carAttrs = {"4 wheels", "engine", "passenger"};
const set<string> bikeAttrs = {"2 wheels", "engine"};
const set<string> truckAttrs = {"6 wheels", "cargo"};
const set<string> busAttrs = {"4 wheels", "engine", "public transport"};
if (includes(v.attrs.begin(), v.attrs.end(), carAttrs.begin(), carAttrs.end())) {
return "car";
}
if (includes(v.attrs.begin(), v.attrs.end(), bikeAttrs.begin(), bikeAttrs.end())) {
return "bike";
}
if (includes(v.attrs.begin(), v.attrs.end(), truckAttrs.begin(), truckAttrs.end())) {
return "truck";
}
if (includes(v.attrs.begin(), v.attrs.end(), busAttrs.begin(), busAttrs.end())) {
return "bus";
}
return "unknown vehicle";
}
int main() {
Vehicle v1{"V1", {"4 wheels", "engine", "passenger"}};
Vehicle v2{"V2", {"2 wheels", "engine"}};
cout << v1.name << " is " << classifyVehicle(v1) << '\n';
cout << v2.name << " is " << classifyVehicle(v2) << '\n';
return 0;
}