fix printScore
This commit is contained in:
parent
2acdae42e4
commit
4f65ec59e8
57
main.cpp
57
main.cpp
@ -277,22 +277,6 @@ int normalize(char c) {
|
||||
return toLowerCase(c) - 'a';
|
||||
}
|
||||
|
||||
void swap(myPair<char, myPair<int, bool> > *a, int i, int j) {
|
||||
myPair<char, myPair<int, bool> > temp = a[i];
|
||||
a[i] = a[j];
|
||||
a[j] = temp;
|
||||
}
|
||||
|
||||
void bubbleSort(myPair<char, myPair<int, bool> > *a) {
|
||||
for (int i = 0; i < 25; i++) {
|
||||
for (int j = 0; j < 25 - i; j++) {
|
||||
if (a[j].second.first > a[j + 1].second.first)
|
||||
swap(a, j, j + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printScores(int *points, char blacklist) {
|
||||
myPair<char, myPair<int, bool> > *arr = static_cast<myPair<char, myPair<int, bool> > *>(alloc(
|
||||
26 * sizeof(myPair<char, myPair<int, bool> >)));
|
||||
@ -307,31 +291,32 @@ void printScores(int *points, char blacklist) {
|
||||
arr[i] = p;
|
||||
}
|
||||
|
||||
|
||||
int maxScore = -1;
|
||||
int maxCount = 0;
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (arr[i].second.first == -1) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 26; j++) {
|
||||
if (arr[j].second.first == -1 || arr[j].first == arr[i].first) {
|
||||
continue;
|
||||
}
|
||||
if (arr[i].second.first == arr[j].second.first) {
|
||||
arr[i].second.second = true;
|
||||
arr[j].second.second = true;
|
||||
}
|
||||
if (arr[i].second.first > maxScore) {
|
||||
maxScore = arr[i].second.first;
|
||||
maxCount = 1;
|
||||
} else if (arr[i].second.first == maxScore) {
|
||||
maxCount++;
|
||||
}
|
||||
}
|
||||
|
||||
bubbleSort(arr);
|
||||
|
||||
for (int i = 25; i > -1; i--) {
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if (arr[i].second.first != -1) {
|
||||
pt "Player " << arr[i].first << " has " << arr[i].second.first << " boxes" << (
|
||||
(i == 25 || arr[i].second.second) && arr[i].first != blacklist
|
||||
? arr[i].second.second
|
||||
? " (tie)\n"
|
||||
: " (win)\n"
|
||||
: nl);
|
||||
pt "Player " << arr[i].first << " has " << arr[i].second.first << (arr[i].second.first < 2
|
||||
? " box"
|
||||
: " boxes");
|
||||
if (arr[i].second.first == maxScore) {
|
||||
if (maxCount > 1) {
|
||||
pt " (tie)";
|
||||
} else if (arr[i].first != blacklist) {
|
||||
pt " (win)";
|
||||
}
|
||||
}
|
||||
pt nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user