题意:给出考生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. pandas 选取数据 修改数据 loc iloc []

    pandas选取数据可以通过 loc iloc  [] 来选取 使用loc选取某几列: user_fans_df = sample_data.loc[:,['uid','fans_count']] 使 ...

  2. 【转】Java设计模式-单例模式详解

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6510196.html 所谓单例,指的就是单实例,有且仅有一个类实例,这个单例不应该由人来控 ...

  3. colorlog的三个例子

    例1:默认的log_colors import logging from logging.handlers import RotatingFileHandler from colorlog impor ...

  4. JSON字符串与JSON对象的互相转换

    比如工作中遇到的app强制退出功能的参数问题 首先定义一个JSON字符串 objectStr : String value=UUID.randomUUID().toString();SimpleDat ...

  5. Pro C/C++ 编程中值得注意的问题

    1.宿主字符串存储Oracle自动补零问题. EXEC SQL BEGIN DECLARE SECTION; unsigned char liId[25]; EXEC SQL END DECLARE ...

  6. Updated: Database Partitioning with EBS Whitepaper

    Partitioning allows a single database table and its associated indexes to be broken into smaller com ...

  7. 012——VUE中todos示例讲解class中应用表达式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. nivicat premium连接阿里云数据库

    1.首先打开Navicat,文件>新建连接>MySQL连接,其他的如一图所示 其中: 连接名:自己取一个名字 主机名:填写mysql的地址 用户名:mysql的登录的用户名 密码:登录的密 ...

  9. 你真的对java static了解吗,代码优化可能更加简单

    static修饰的成员变量和成员方法独立于该类的任何对象.也就是说,它不依赖类特定的实例,被类的所有实例共享. 只要这个类被加载,Java虚拟机就能根据类名在运行时数据区的方法区内定找到他们.因此,s ...

  10. C++ Primer 第四版中文版

    C++Primer是C++的经典教程. 开始时间:2014-08-10 完成时间:2014-08-28 学习成果:基础语法+