-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPotW1.cpp
More file actions
69 lines (49 loc) · 1.83 KB
/
PotW1.cpp
File metadata and controls
69 lines (49 loc) · 1.83 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
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
void fill_vector(int, vector< pair <string, unsigned long int>>&);
void find_match(vector< pair <string, unsigned long int>>, pair<string, string>&, pair<string, string>&);
void print_users(pair <string, string>, pair <string, string>);
int main () {
int num_users;
vector <pair <string,unsigned long int>> users;
pair <string, string> best_match, worst_match;
cin >> num_users;
fill_vector(num_users, users);
find_match(users, best_match, worst_match);
print_users(best_match, worst_match);
return 0;
}
void fill_vector(int size, vector< pair <string, unsigned long int>>& users) {
pair <string, unsigned long int> cur_user;
for (int i = 0; i < size; i++) { //fill vector with users
cin >> cur_user.first >> cur_user.second;
users.push_back(cur_user);
}
}
void find_match(vector< pair <string, unsigned long int>> users, pair<string, string>& best_match, pair<string, string>& worst_match) {
bitset<32> best = 4294967295, worst = 0, check; //highest unsigned long value, lowest unsigned long value
for (auto x : users) {
for (auto y : users) {
if (x.first == y.first) //check if comparing a user to itself
continue;
check = x.second ^ y.second;
//cout << best.to_string() << endl << "SIZE: " << best.size() << endl;
if (check.count() < best.count()) { //check if two users are the best match
best_match.first = x.first;
best_match.second = y.first;
best = check;
}
if (check.count() > worst.count()) { //check if two users are the worst match
worst_match.first = x.first;
worst_match.second = y.first;
worst = check;
}
}
}
}
void print_users(pair<string, string> best, pair<string, string> worst) {
cout << best.first << " " << best.second << "\n"
<< worst.first << " " << worst.second << "\n";
}