-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
54 lines (50 loc) · 1.37 KB
/
utils.cpp
File metadata and controls
54 lines (50 loc) · 1.37 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
#include "utils.h"
bool find(string s, vs strings) {
for (size_t i = 0; i != strings.size(); i++) if (s == strings[i]) return true;
return false;
}
string check(string& s, istringstream& i, int& n, int l, int h, bool& timesUp, vs strings) {
i.str(s);
while (!timesUp && !find(s, strings) && (s.find(' ') != s.npos || !(i >> n) || n < l || n > h)) {
cout << "Invalid input. Try again: ";
getline(cin, s);
i.clear();
i.str(s);
}
i.clear();
return s;
}
pair<string, aRecord> aCreate(string& s, istringstream& i) {
aRecord aRec;
int n = 0, count = 0;
while (s[count] != ':') count++;
string name = s.substr(n, count);
n = count + 2;
while (s[count] != 'H') count++;
i.str(s.substr(n, count));
i >> aRec.hard;
i.clear();
n = count + 3;
while (s[count] != 'M') count++;
i.str(s.substr(n, count));
i >> aRec.medium;
i.clear();
n = count + 3;
while (s[count] != 'E') count++;
i.str(s.substr(n, count));
i >> aRec.easy;
i.clear();
return {name, aRec};
}
pair<string, int> fCreate(string& s, istringstream& i) {
int n = 0, count = 0;
while (s[count] != ':') count++;
string name = s.substr(n, count);
n = count + 2;
count += 2;
while (s[count] != ' ') count++;
i.str(s.substr(n, count));
i >> n;
i.clear();
return {name, n};
}