-
Notifications
You must be signed in to change notification settings - Fork 1
/
rankedteam.cpp
64 lines (54 loc) · 1.56 KB
/
rankedteam.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
#include "rankedteam.h"
namespace DJ {
namespace Model {
RankedTeam::RankedTeam(QString id, QString name, QObject *parent) : QObject(parent) {
this->id = id;
this->name = name;
}
void RankedTeam::setProblem(QString id, RankedProblem *problem, Contest *contest) {
if (problemsHash.contains(id)) {
// First remove old one
int idx = problemsHash[id];
delete problems[idx];
// Now replace with new problem
problems.replace(idx, problem);
} else {
problems.append(problem);
problemsHash[id] = problems.size() - 1;
}
this->recalculateData(contest);
}
void RankedTeam::recalculateData(Contest *contest) {
this->numSolved = 0;
this->totalTime = 0;
for (int i = 0; i < this->problems.size(); i++) {
RankedProblem *problem = this->problems.at(i);
if (problem->problemState == SOLVED) {
this->numSolved++;
this->totalTime += problem->timeFirstCorrectTry + (contest->getPenaltyMinutes() * (problem->tries - 1));
}
}
}
int RankedTeam::getNumSolved() {
return this->numSolved;
}
int RankedTeam::getTotalTime() {
return this->totalTime;
}
QString RankedTeam::getName() {
return this->name;
}
QString RankedTeam::getId() {
return this->id;
}
int RankedTeam::getNumProblems() {
return this->problems.size();
}
RankedProblem *RankedTeam::getProblem(int i) {
return this->problems.at(i);
}
RankedProblem *RankedTeam::getProblemById(QString id){
return this->problems.at(this->problemsHash[id]);
}
} // namespace Model
} // namespace DJ