题意:给出考生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. Mybatis报错Cause: org.apache.ibatis.executor.ExecutorException: Executor was closed.

    SqlSession被关闭了,检查是否使用了被关闭的SqlSession.

  2. 图片qq浏览器不显示,微信显示问题原因

    1.qq浏览器关闭云加速就可以了

  3. 一 web爬虫,requests请求

    requests请求,就是用python的requests模块模拟浏览器请求,返回html源码 模拟浏览器请求有两种,一种是不需要用户登录或者验证的请求,一种是需要用户登录或者验证的请求 一.不需要用 ...

  4. HDU 4725 建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4725 The Shortest Path in Nya Graph Time Limit: 2000/1000 ...

  5. js获取一周的日期范围

    function getWeek() { this.nowTime = new Date(); this.init = function() { this.dayInWeek = this.nowTi ...

  6. Agilent RF fundamentals (4)- Impedance match and distortions

    1 Impedance match: 2 distortions: Solar radiation produces background noise

  7. C#实现文件与二进制互转并存入数据库

    这篇文章主要介绍了C#实现文件与二进制互转并存入数据库,本文直接给出代码实例,代码中包含详细注释,需要的朋友可以参考下 //这个方法是浏览文件对象     private void button1_C ...

  8. linux中文件或者文件夹的基本操作(复制,移动,删除,查找,压缩)

    linux 文件(文件夹)的创建,复制,移动,重命名,删除基本命令 复制文件或整个目录 cp 源文件名 目标文件夹/[目标文件名]cp -rv 源文件夹 目标文件夹/[目标文件夹名] --r 递归目录 ...

  9. 细说 const

    1.const 简单应用 const int pp=0 //pp 为整形常量,不能修改 还有另外一种不常用的方式 但是最容易误导 int const pp=0 //pp 为整形常量,不能修改 记住这两 ...

  10. 抛弃Https让Cas以Http协议提供单点登录服务

    本文环境: 1.apache-tomcat-7.0.50-windows-x86 2.cas-server-3.4.11 3.cas-client-3.2.1 将cas-server-webapp-3 ...