-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
85 lines (72 loc) · 1.94 KB
/
main.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
#include "GroupStage.h"
#include "FinalStage.h"
Group* distributionInGroups(Team* arrTeams, int numTeams, int& numGroups)
{
int remainder;
if (numTeams % 4 == 0)
{
numGroups = numTeams / 4;
remainder = 0;
}
else if (numTeams % 4 == 1)
{
numGroups = (numTeams - 9) / 4 + 3;
remainder = 3;
}
else if (numTeams % 4 == 2)
{
numGroups = (numTeams - 6) / 4 + 2;
remainder = 2;
}
else
{
numGroups = (numTeams - 3) / 4 + 1;
remainder = 1;
}
int jumpInTeams = 0;
Group* groupsInTournament = new Group[numGroups];
assert(groupsInTournament);
for (int i = 0; i < numGroups - remainder; i++)
{
groupsInTournament[i].setTeams(arrTeams + jumpInTeams, 4);
jumpInTeams += 4;
}
for (int i = numGroups - remainder; i < numGroups; i++)
{
groupsInTournament[i].setTeams(arrTeams + jumpInTeams, 3);
jumpInTeams += 3;
}
return groupsInTournament;
}
int main()
{
int numTeams;
int numGroups;
std::cout << "Enter the number of teams:";
std::cin >> numTeams;
std::cout << std::endl;
Team** arrTeams = new Team*[numTeams];
assert(arrTeams);
for (int i = 0; i < numTeams; i++)
{
char nameOfTeam[100];
int pointsOfTeam;
std::cout << "Enter the name of the " << i + 1 << "-st team: ";
std::cin.ignore();
std::cin.getline(nameOfTeam, 100, '\n');
std::cout << std::endl;
std::cout << "Enter the points of the " << i + 1 << "-st team: ";
std::cin >> pointsOfTeam;
std::cout << std::endl;
arrTeams[i] = new Team(nameOfTeam, pointsOfTeam);
assert(arrTeams[i]);
}
Group* arrGroups = distributionInGroups(*arrTeams, numTeams, numGroups);
GroupStage groupStage(arrGroups, numGroups);
groupStage.playMatch();
groupStage.GroupStageSort();
FinalStage finalStage(*groupStage.getRankedTeams(), numTeams);
if (!finalStage.getPowerOfTwo()) finalStage.selectionPowerTwo(*groupStage.getRankedTeams(), numTeams);
finalStage.finalStageSort();
return 0;
}