Created
October 20, 2017 07:46
-
-
Save TheRoyalDebugger/8db3540ebae2059b751b2acd0c4c8790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cmath> | |
| #include <cstdio> | |
| #include <vector> | |
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| struct Player { | |
| string name; | |
| int score; | |
| }; | |
| int getPartitionPoint(vector<Player> &players,int low ,int high){ | |
| int pivot = players[high].score; | |
| while(low < high){ | |
| while(players[low].score < pivot){ | |
| low++; | |
| } | |
| while(players[high].score > pivot){ | |
| high--; | |
| } | |
| if(players[low].score == players[high].score){ | |
| if(players[low].name < players[high].name){ | |
| Player temp = players[low]; | |
| players[low] = players[high]; | |
| players[high] = temp; | |
| } | |
| low++; | |
| }else{ | |
| if(low < high){ | |
| Player temp = players[low]; | |
| players[low] = players[high]; | |
| players[high] = temp; | |
| } | |
| } | |
| } | |
| return high; | |
| } | |
| void quickSort(vector<Player> &players,int low ,int high){ | |
| if(low < high){ | |
| int partitionIndex = getPartitionPoint(players,0,high); | |
| quickSort(players,low,partitionIndex-1); | |
| quickSort(players,partitionIndex+1,high); | |
| } | |
| } | |
| vector<Player> comparator(vector<Player> players) { | |
| quickSort(players,0,players.size()-1); | |
| return players; | |
| } | |
| int main() { | |
| int n; | |
| cin >> n; | |
| vector< Player > players; | |
| string name; | |
| int score; | |
| for(int i = 0; i < n; i++){ | |
| cin >> name >> score; | |
| Player p1; | |
| p1.name = name, p1.score = score; | |
| players.push_back(p1); | |
| } | |
| vector<Player > answer = comparator(players); | |
| for(int i = answer.size()-1; i >=0; i--) { | |
| cout << answer[i].name << " " << answer[i].score << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment