题意:给出考生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. NLP(二)_汉语言分词技术-最大匹配法

    前述 词是自然语言中最小的有意义的构成单位.汉语文本是基于单字的文本,汉语的书面表达方式以汉字作为最小单元,词与词之间没有明显的界限标志,因此,分词是汉语文本分析处理中首先要解决的问题之一. 分词可能 ...

  2. 一般处理程序ashx中用session存储数据

    如果要使用session的话,在handler的代码中添加System.Web.SessionState的引用,并让这个handler继承IRequiresSessionState接口,一定要继承这个 ...

  3. C#笔记之 函数可变参数

    (转自:http://blog.csdn.net/jackluangle/article/details/6539278) 其实函数的参数的可变是因为不确定函数的参数大小的原因才使用的.看下面一个列子 ...

  4. LeetCode OJ:Pascal's Triangle(帕斯卡三角)

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  5. react_webpack.prod.config

    const path = require('path'); const webpack = require('webpack'); const jquery = require('jquery'); ...

  6. Spring-Kafka 2.0.0发送API翻译

    Kafka Template–2.2.0 api KafkaTemplate KafkaTemplate这个类包装了个生产者,来提供方便的发送数据到kafka的topic里面. 同步和异步的方法都有, ...

  7. Kotlin Android Extensions (译文)

    原文链接: http://kotlinlang.org/docs/tutorials/android-plugin.html Kotlin Android Extensions 本教程介绍如何使用Ko ...

  8. tslib: Selected device is not a touchscreen (must support ABS_X and ABS_Y events)

    /************************************************************************************ * tslib: Selec ...

  9. NGINX 配置文件配置url重写

    1.项目在根目录: location / {            index  index.html index.htm index.php l.php;            autoindex  ...

  10. Requst Servervariables

    Request.ServerVariables("Url") 返回服务器地址 Request.ServerVariables("Path_Info") 客户端提 ...