mirror of
https://github.com/Estom/notes.git
synced 2026-04-05 03:48:56 +08:00
并发编程
This commit is contained in:
43
code_segment/xioayu2.cpp
Normal file
43
code_segment/xioayu2.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
class Solution{
|
||||
|
||||
public:
|
||||
std::vector<std::string> scoresort(std::vector<std::string> names,std::vector<std::string> scores){
|
||||
map<int,int> m;
|
||||
for(int i=0;i<scores.size();i++){
|
||||
istringstream ss(scores[i]);
|
||||
string temp;
|
||||
int sum=0;
|
||||
while(getline(ss,temp,',')){
|
||||
sum+=atoi(temp.c_str());
|
||||
}
|
||||
m[sum]=i;
|
||||
}
|
||||
vector<string> res;
|
||||
for(auto beg=m.rbegin();beg!=m.rend();beg++){
|
||||
res.push_back(names[beg->second]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Solution s;
|
||||
using namespace std;
|
||||
vector<string> names{"1","2","3"};
|
||||
vector<string> scores{"1,2,3","3,4,5","6,7,8"};
|
||||
|
||||
vector<string> res = s.scoresort(names,scores);
|
||||
for(auto a:res){
|
||||
cout<<a<<" ";
|
||||
}
|
||||
cout<<endl;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user