forked from georgiavachon/EC327-SmartList
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.h
More file actions
189 lines (165 loc) · 4.94 KB
/
Copy pathAlgorithm.h
File metadata and controls
189 lines (165 loc) · 4.94 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright Ayrton Reulet 2021 reulayrt@bu.edu
// Copyright Megan Freeman 2021 megfree@bu.edu
// Copyright Dasha Smolina 2021 dsmolina@bu.edu
// Copyright Georgia Vachon gvachon@bu.edu
#pragma once
using std::vector;
using std::string;
using std::stoi;
// makes all the dates go back to normal
void back2Normal(vector<vector<string>> &p) {
vector<string> month, day;
for (auto e : p) {
string tmonth, tday;
for (int j = 0; j<2; j++) {
tmonth += e.at(0).at(j);
}
for (int j = 3; j<5; j++) {
tday += e.at(0).at(j);
}
month.push_back(tmonth);
day.push_back(tday);
}
for (int i = 0; i < month.size(); i++) {
if (day.at(i) == "00") {
month.at(i) = std::to_string(stoi(month.at(i))-1);
month.at(i).insert(month.at(i).begin(), 1, '0');
if (month.at(i) == "01" || month.at(i) == "03" || month.at(i) == "05" || month.at(i) == "07"
|| month.at(i) == "08" || month.at(i) == "10" || month.at(i) == "12") {
day.at(i) = "31";
}
else if (month.at(i) == "04" || month.at(i) == "06" || month.at(i) == "09"
|| month.at(i) == "11") {
day.at(i) = "30";
}
else if (month.at(i) == "02") {
day.at(i) = "28";
}
}
}
for (int i = 0; i < month.size(); i++) {
p.at(i).at(0) = month.at(i) + "/" + day.at(i);
}
}
// turn the exceptions into a new day 0
void dayZero(vector<vector<string>> &exception) {
vector<string> month, day;
for (int i = 0; i < exception.size(); i++) {
string tmonth, tday;
//month
for (int j = 0; j < 2; j++) {
tmonth += exception.at(i).at(0).at(j);
}
month.push_back(tmonth);
//day
for (int j = 3; j < 5; j++) {
tday += exception.at(i).at(0).at(j);
}
day.push_back(tday);
}
for (int i = 0; i < month.size(); i++) {
month.at(i) = std::to_string(stoi(month.at(i)) + 1);
month.at(i).insert(month.at(i).begin(), 1, '0');
day.at(i) = "00";
}
for (int i = 0; i < month.size(); i++) {
exception.at(i).at(0) = month.at(i) + "/" + day.at(i);
}
}
// exceptions for the 12 days of the year that don't work with the normal algorithm
vector<vector<string>> exceptions(vector<vector<string>> &p, vector<float> month,
vector<float> day, vector<float> priority) {
vector<vector<string>> exception;
int counter = 0;
for (int i = 0; i < month.size(); i++) {
if (priority.at(i) < 6) {
// 31 days
if ((month.at(i) == 1 || month.at(i) == 3 || month.at(i) == 5 || month.at(i) == 7
|| month.at(i) == 8 || month.at(i) == 10 || month.at(i) == 12) && (day.at(i) == 31)) {
exception.push_back(p.at(i-counter));
p.erase(p.begin()+i-counter);
counter++;
}
// 30 days
else if ((month.at(i) == 4 || month.at(i) == 6 || month.at(i) == 9 || month.at(i) == 11)
&& (day.at(i) == 30)) {
exception.push_back(p.at(i-counter));
p.erase(p.begin()+i-counter);
counter++;
}
// 28 days
else if (month.at(i) == 2 && day.at(i) == 28) {
exception.push_back(p.at(i-counter));
p.erase(p.begin()+i-counter);
counter++;
}
}
}
dayZero(exception);
return exception;
}
// Normal ordering Algorithm
void order(vector<vector<string>> &p, vector<float> month, vector<float> day, vector<float> priority) {
vector<vector<string>> finder;
finder = p;
int n = p.size();
vector<float> mag(n), old;
for (int i = 0; i < month.size(); i++) {
mag.at(i) = ((13-month.at(i))*500) + ((31-day.at(i))*4.9) + (priority.at(i));
for (int j = 0; j < i; j++) {
if (mag.at(i) == mag.at(j)) {
mag.at(i) = mag.at(i) + 0.01;
}
}
}
old = mag;
sort(mag.begin(),mag.end(), std::greater<int>());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (mag.at(i) == old.at(j)) {
p.at(i) = finder.at(j);
}
}
}
}
// Function that gets used in the main program
vector<vector<string>> algorithm(vector<vector<string>> &p) {
vector<float> Emonth, Eday, Epriority;
vector<vector<string>> exception;
for (int i = 0; i < p.size(); i++) {
string tMonth, tDay, tPriority;
// Months
for (int j = 0; j < 2; j++) {
tMonth += p.at(i).at(0).at(j);
}
Emonth.push_back(stoi(tMonth));
// Days
for (int j = 3; j < 5; j++) {
tDay += p.at(i).at(0).at(j);
}
Eday.push_back(stoi(tDay));
Epriority.push_back(stoi(p.at(i).at(2)));
}
exception = exceptions(p, Emonth, Eday, Epriority);
vector<float> month, day, priority;
for (auto e : exception) {
p.push_back(e);
}
for (int i = 0; i < p.size(); i++) {
string tMonth, tDay, tPriority;
// Months
for (int j = 0; j < 2; j++) {
tMonth += p.at(i).at(0).at(j);
}
month.push_back(stoi(tMonth));
// Days
for (int j = 3; j < 5; j++) {
tDay += p.at(i).at(0).at(j);
}
day.push_back(stoi(tDay));
priority.push_back(stoi(p.at(i).at(2)));
}
order(p, month, day, priority);
back2Normal(p);
return p;
}