又做了一些

This commit is contained in:
carry
2025-01-02 18:57:27 +08:00
parent 759c5b09ce
commit 6aeaa7fda6
3 changed files with 129 additions and 14 deletions

36
rankTeams.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution {
public:
string rankTeams(vector<string>& votes) {
unordered_map<char,int> list;
for(auto i : votes){
for(int j = 0;j < i.size();j++){
list[i[j]] += i.size() - j;
}
}
string res;
vector<pair<char,int>> temp(list.begin(),list.end());
stable_sort(temp.begin(),temp.end(),[](pair<char,int> a,pair<char,int> b){
return a.second > b.second;
});
for(auto i : temp){
res += i.first;
}
return res;
}
};
int main(){
vector<string> votes = {"WXYZ","XYZW"};
Solution s;
cout << s.rankTeams(votes) << endl;
return 0;
}