A 1141 PAT Ranking of Institutions (25分)
Posted tsruixi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A 1141 PAT Ranking of Institutions (25分)相关的知识,希望对你有一定的参考价值。
一、技术总结
二、参考代码
#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分)的主要内容,如果未能解决你的问题,请参考以下文章
1141 PAT Ranking of Institutions PAT甲级
1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25)
1141 PAT Ranking of Institutions (25 分)难度: 一般 / 知识点: 排序