https://pintia.cn/problem-sets/994805260223102976/problems/994805260353126400
一个学校的结构体数组,下标从1开始分配
读入数据时,用map检测学校是否出现过,如果没有出现过,就分配新的下标,否则就用以前的下标
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
struct node1{
string name, school;
double min, max;
};
struct node2{
string school_name;
double score = 0.0;
int count = 0;
};
string Atoa(string a){
for(int i = 0; i < a.size();i++)
a[i] = (a[i] >= 'A' && a[i] <= 'Z') ? (a[i]-'A'+'a') : a[i];
return a;
}
bool cmp(node2 a, node2 b){
if((int)a.score != (int)b.score) return a.score > b.score;
else if(a.count != b.count) return a.count < b.count;
else return a.school_name < b.school_name;
}
map<string, int> match;
node1 stu[100010];
node2 sch[100010];
int main(){
int N, score, sub = 0, tmp;
string t_num, t_school;
cin >> N;
for(int i = 0; i < N; i++){
cin >> stu[i].name >> stu[i].max >> stu[i].school;
stu[i].school = Atoa(stu[i].school);
if(stu[i].name[0] == 'B') stu[i].min = stu[i].max / 1.5;
else if(stu[i].name[0] == 'A') stu[i].min = stu[i].max;
else if(stu[i].name[0] == 'T') stu[i].min = stu[i].max * 1.5;
if(!match[stu[i].school]){
tmp = ++sub;
match[stu[i].school] = tmp;
}
else
tmp = match[stu[i].school];
sch[tmp].school_name = stu[i].school;
sch[tmp].score += stu[i].min;
sch[tmp].count++;
}
sort(sch+1, sch+sub+1, cmp);
cout << sub << endl;
for(int i = 1; i <= sub; i++){
int cnt = 0;
for(int j = i; j <= sub && ((int)sch[i].score == (int)sch[j].score) ; j++, cnt++)
cout << i << " " << sch[j].school_name << " " << (int)sch[j].score << " " << sch[j].count << endl;
i += --cnt;
}
return 0;
}