fix logical err in win/tie

This commit is contained in:
Sandipsinh Rathod 2024-10-10 19:55:31 -04:00
parent 489c43b953
commit 7138acc056

@ -199,16 +199,16 @@ int normalize(char c) {
return toLowerCase(c) - 'a'; return toLowerCase(c) - 'a';
} }
void swap(pair<char, int> *a, int i, int j) { void swap(pair<char, pair<int, bool> > *a, int i, int j) {
pair<char, int> temp = a[i]; pair<char, pair<int, bool> > temp = a[i];
a[i] = a[j]; a[i] = a[j];
a[j] = temp; a[j] = temp;
} }
void bubbleSort(pair<char, int> *a) { void bubbleSort(pair<char, pair<int, bool> > *a) {
for (int i = 0; i < 25; i++) { for (int i = 0; i < 25; i++) {
for (int j = 0; j < 25 - i; j++) { for (int j = 0; j < 25 - i; j++) {
if (a[j].second > a[j + 1].second) if (a[j].second.first > a[j + 1].second.first)
swap(a, j, j + 1); swap(a, j, j + 1);
} }
} }
@ -216,25 +216,40 @@ void bubbleSort(pair<char, int> *a) {
void printScores(int *points, char blacklist) { void printScores(int *points, char blacklist) {
pair<char, int> *arr = static_cast<pair<char, int> *>(alloc(26 * sizeof(pair<char, int>))); pair<char, pair<int, bool> > *arr = static_cast<pair<char, pair<int, bool> > *>(alloc(
26 * sizeof(pair<char, pair<int, bool> >)));
for (int i = 0; i < 26; i++) { for (int i = 0; i < 26; i++) {
pair<char, int> p; pair<char, pair<int, bool> > p;
pair<int, bool> p1;
p1.first = points[i];
p1.second = false;
p.first = static_cast<char>(i + 'A'); p.first = static_cast<char>(i + 'A');
p.second = points[i]; p.second = p1;
arr[i] = p; arr[i] = p;
} }
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;
}
}
}
bubbleSort(arr); bubbleSort(arr);
int prev = -1;
string win = arr[25].second == arr[24].second ? " (tie)\n" : " (win)\n";
for (int i = 0; i < 26; i++) { for (int i = 0; i < 26; i++) {
if (arr[i].second != -1) { if (arr[i].second.first != -1) {
pt arr[i].first << ": " << arr[i].second << " boxes" << ( pt arr[i].first << ": " << arr[i].second.first << " boxes" << (
(i == 25 || prev == arr[i].second) && arr[i].first != blacklist ? win : nl); (i == 25 || arr[i].second.second) && arr[i].first != blacklist ? arr[i].second.second ? " (tie)\n": " (win)\n" : nl);
prev = arr[i].second;
} }
} }