标签:stream += return back vector algo pac bool cout
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
struct node_i{
string name;
double all_score;
int num;
};
bool cmp(node_i a, node_i b){
if(a.all_score != b.all_score) return a.all_score > b.all_score;
else if(a.num != b.num) return a.num < b.num;
else return a.name < b.name;
}
int main(){
int n, index = 0;
vector<node_i> v;
map<string, int> f;
set<string> e_sch;
scanf("%d", &n);
for(int i = 0; i < n; i++){
string s, sch;
double sc;
cin >> s >> sc >> sch;
transform(sch.begin(), sch.end(), sch.begin(), ::tolower);
if(e_sch.find(sch) != e_sch.end()){
if(s[0] == ‘B‘) v[f[sch]].all_score += sc/1.5;
else if(s[0] == ‘A‘) v[f[sch]].all_score += sc;
else v[f[sch]].all_score += sc*1.5;
v[f[sch]].num++;
}else{
double temp_sc;
if(s[0] == ‘B‘) temp_sc = sc/1.5;
else if(s[0] == ‘A‘) temp_sc = sc;
else temp_sc = sc*1.5;
v.push_back(node_i{sch, temp_sc, 1});
e_sch.insert(sch);
f[sch] = index++;
}
}
for(int i = 0; i < v.size(); i++){
v[i].all_score = int(v[i].all_score);
}
sort(v.begin(), v.end(), cmp);
int rank;
cout << e_sch.size() << endl;
for(int i = 1; i <= v.size(); ++i){
if(i != 1 && v[i-1].all_score == v[i-2].all_score){
cout << rank << " " << v[i-1].name << " " << int(v[i-1].all_score) << " " << v[i-1].num << endl;
}else{
cout << i << " " << v[i-1].name << " " << int(v[i-1].all_score) << " " << v[i-1].num << endl;
rank = i;
}
}
return 0;
}
A 1141 PAT Ranking of Institutions (25分)
标签:stream += return back vector algo pac bool cout
原文地址:https://www.cnblogs.com/tsruixi/p/13160760.html