题意:给出考生id(分为乙级、甲级和顶级),取得的分数和所属学校。计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数。最后对学校进行排名。

思路:本题的研究对象是学校,而不是考生!因此,建立学校的结构体Record,记录学校的校名,考生人数,排名,成绩等信息。利用map<校名,该学校对应的结构体>构造映射,然后在读入数据的时候就可以更新该学校的分数,学生人数。数据读入完毕后,根据计算规则求出各个学校的带权总成绩,再把结构体放到vector中排序一下,确定排名,就好了。

代码:

#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

struct Record{
    int rank;
    string sch;
    int ScoreB,ScoreA,ScoreT,tws;
    int cnt;
    Record():rank(),sch(),ScoreA(),ScoreT(),tws(),cnt(){}
};
map<string,Record> mp;
vector<Record> vec;

bool cmp(Record a,Record b)
{
    if(a.tws!=b.tws) return a.tws>b.tws;
    else if(a.cnt!=b.cnt) return a.cnt<b.cnt;
    else return a.sch<b.sch;
}

int main()
{
    //ifstream cin("pat.txt");
    int n;
    cin>>n;
    string sch,id;
    int score;
    ;i<n;i++){
        cin>>id>>score>>sch;
        ;i<sch.size();i++)
            sch[i]=tolower(sch[i]);
        mp[sch].cnt++;
        mp[sch].sch=sch;
        ]=='B') mp[sch].ScoreB+=score;
        ]=='A') mp[sch].ScoreA+=score;
        else mp[sch].ScoreT+=score;
    }
    for(auto it:mp){
        Record rec=it.second;
        rec.tws=rec.ScoreB/1.5 + rec.ScoreA + rec.ScoreT*1.5;
        vec.push_back(rec);
    }
    sort(vec.begin(),vec.end(),cmp);
    ;i<vec.size();i++){
        ) vec[i].rank=;
        ].tws) vec[i].rank=vec[i-].rank;
        ;
    }
    cout<<vec.size()<<'\n';
    for(auto it:vec)
        cout<<it.rank<<' '<<it.sch<<' '<<it.tws<<' '<<it.cnt<<'\n';
    ;
}

1141 PAT Ranking of Institutions的更多相关文章

  1. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

  2. PAT 甲级 1141 PAT Ranking of Institutions

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...

  3. [PAT] 1141 PAT Ranking of Institutions(25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  4. 1141 PAT Ranking of Institutions (25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  5. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  6. PAT_A1141#PAT Ranking of Institutions

    Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...

  7. A1141. PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  8. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  9. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

随机推荐

  1. T-SQL RIGHT JOIN

    RIGHT JOIN外联接与LEFT JOIN相似.取得右表所有记录,并按过滤条件ON去取得左表的记录,取得这些记录,如遇上没有匹配的列使用NULL填充. 演示数据来源,两张表来自http://www ...

  2. MyBatis学习(3)

    MyBatis-逆向工程 Mybatis工作原理 一个MapperStatement代表一个封装改查标签的详细信息. Configuration对象保存了所有配置文件的详细信息. 总结:把配置文件的信 ...

  3. 智课雅思词汇---二十三、名词性后缀mony

    智课雅思词汇---二十三.名词性后缀mony 一.总结 一句话总结:Latin: action, result of an action or condition; a suffix that for ...

  4. JavaEE 技术体系

    JavaEE 技术体系总结: 一:常见模式与工具 设计模式,流行的框架与组件 常见的设计模式,编码必备 Spring5,做应用必不可少的最新框架 MyBatis,玩数据库必不可少的组件 二:工程化与工 ...

  5. poj32072-sat模板题

    tarjan扫一遍后直接判断 最关键的地方就是建边(x[i] <= x[j] && y[i] >= x[j] && y[i] <= y[j]) || ...

  6. datagrid中用tooltip

    function msgFormat(value,row){ value = value.replace(/ /g," "); return '<span title='+ ...

  7. sizeof结构体

    规则1:结构体的对折长度为其基本数据成员的长度的最大值. 规则2:指定边界情况下,结构体的对折长度为自身对折长度和指定对折长度中较小者. 规则3:当行内结构体的基本数据成员的起始地址必须为其长度的整数 ...

  8. 基于Spring MVC实现基于form表单上传Excel文件,批量导入数据

    在pom.xml中引入: <!--处理2003 excel--> <dependency> <groupId>org.apache.poi</groupId& ...

  9. mongodb集群——配置服务器放分片meta信息,说明meta里包含了哪些数据信息

    在搭建分片之前,先了解下分片中各个角色的作用. ① 配置服务器.是一个独立的mongod进程,保存集群和分片的元数据,即各分片包含了哪些数据的信息.最先开始建立,启用日志功能.像启动普通的mongod ...

  10. Swagger实践和总结

    Swagger学习和实践 最近安装并使用了一下Swagger-ui.Swagger-editor和Swagger-codegen,感觉还不错. Swagger 是一个规范和完整的框架,用于生成.描述. ...