-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFantasyDraft.cpp
97 lines (81 loc) · 2.74 KB
/
FantasyDraft.cpp
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
using namespace std;
#include <iostream>
#include <unordered_set>
class Owner {
public:
int Q;
string * preferences;
string * roster;
int index = 0;
};
int main() {
int N, K, P;
cin >> N >> K;
Owner teams[N];
for (int i = 0; i < N; i++) {
cin >> teams[i].Q;
teams[i].preferences = new string[teams[i].Q];
teams[i].roster = new string[K];
for (int j = 0; j < teams[i].Q; j++) {
cin >> teams[i].preferences[j];
}
// for (int j = 0; j < teams[i].Q; j++) {
// cout << teams[i].preferences[j] << " ";
// }
// cout << "\n";
};
cin >> P;
string players[P];
for (int i = 0; i < P; i++) {
cin >> players[i];
}
int playersIndex = 0;
unordered_set<string> taken;
for (int k = 0; k < K; k++) {
// k is the round of the draft
//cout << "Round " << k << "\n";
for (int n = 0; n < N; n++) {
//cout << "Team " << n << "\n";
// teams[n] is the current team
if (teams[n].index < teams[n].Q) {
while ( taken.find( teams[n].preferences[teams[n].index] ) != taken.end()
&& teams[n].index < teams[n].Q ) {
teams[n].index++;
if (teams[n].index >= teams[n].Q) break;
}
}
//cout << "Passed while\n";
if (teams[n].index < teams[n].Q) {
//cout << "If\n";
// not all preferences have been exhausted
teams[n].roster[k] = teams[n].preferences[teams[n].index];
taken.insert(teams[n].roster[k]);
teams[n].index++;
} else { //if (teams[i].index >= teams[i].Q) {
// takes from players list indescriminately
// preferences list has been exhausted
//cout << "Else\n";
while ( taken.find( players[playersIndex] ) != taken.end()
&& playersIndex < P ) {
playersIndex++;
if (playersIndex >= P) break;
}
teams[n].roster[k] = players[playersIndex];
taken.insert(teams[n].roster[k]);
playersIndex++;
}
//cout << teams[n].roster[k] << " " << playersIndex << "\n";
}
}
for (int n = 0; n < N; n++) {
// cout << teams[n].roster << " " << teams[n].preferences << " ";
for (int k = 0; k < K; k++) {
if (k != 0) {
cout << " ";
}
cout << teams[n].roster[k];
}
cout << "\n";
}
return 0;
}