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