题目https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184

题意:

给定几个学生的PAT分数和学校,给这些学校学生的PAT总分排序。

思路:

库函数tolower()和toupper()可以分别把字符串转换为都是小写字母和都是大写字母。

这道题要注意的是,因为是加权的总分,算的时候应该用double。但是题目中有说,总分取加权之后的整数部分,全部加完后要转成int进行比较。

 //#include<bits/stdc++>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdlib.h>
#include<queue>
#include<map>
#include<stack>
#include<set> #define LL long long
#define ull unsigned long long
#define inf 0x7f7f7f7f using namespace std; const int maxn = 1e5 + ;
int n;
struct school{
string name;
int num;
double sco;
int rnk;
}sch[maxn];
set<string>school_name;
set<string>::iterator iter;
map<string, int>schoolid; bool cmp(school &a, school &b)
{
if((int)a.sco == (int)b.sco)
if(a.num == b.num)return a.name < b.name;
else return a.num < b.num;
else return (int)a.sco > (int)b.sco;
} struct student{
string name;
double sco;
string sch;
}stu[maxn]; int main()
{
scanf("%d", &n);
for(int i = ; i < n; i++){
cin>>stu[i].name>>stu[i].sco>>stu[i].sch;
if(stu[i].name[] == 'T')stu[i].sco *= 1.5;
else if(stu[i].name[] == 'B')stu[i].sco /= 1.5;
transform(stu[i].sch.begin(), stu[i].sch.end(), stu[i].sch.begin(), ::tolower);
school_name.insert(stu[i].sch);
}
int id = ;
for(iter = school_name.begin(); iter != school_name.end(); iter++){
string s = *iter;
sch[id].name = s;
schoolid[s] = id++;
} for(int i = ; i < n; i++){
int sid = schoolid[stu[i].sch];
sch[sid].num++;
sch[sid].sco += stu[i].sco;
} sort(sch, sch + id, cmp);
int rnk = , tie = ;
printf("%d\n", id);
for(int i = ; i < id; i++){
sch[i].sco = (int)sch[i].sco;
if(i != && sch[i].sco == sch[i - ].sco){
tie++;
}
else{
rnk += tie + ;
tie = ;
}
cout<<rnk<<" "<<sch[i].name<<" "<<sch[i].sco<<" "<<sch[i].num<<endl;
} return ;
}

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

  1. PAT 甲级 1141 PAT Ranking of Institutions

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

  2. 1141 PAT Ranking of Institutions[难]

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

  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. A1141. PAT Ranking of Institutions

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

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

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

  8. PAT_A1141#PAT Ranking of Institutions

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

  9. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

随机推荐

  1. ionic andorid apk 签名, 查看签名MD5

    ionic cordova build android生成的是带签名的android-debug.apk, 这个是可以在手机上安装的, 但是换个电脑打包这个签名就不一样了, 这样就不能直接替换安装了, ...

  2. Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.

    org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nes ...

  3. [转]numpy 100道练习题

    100 numpy exercise 翻译:YingJoy 网址: https://www.yingjoy.cn/ 来源:https://github.com/rougier/numpy-100 Nu ...

  4. Linux如何统计进程的CPU利用率[转]

    0. 为什么写这篇博客 Linux的top或者ps都可以查看进程的cpu利用率,那为什么还需要了解这个细节呢.编写这篇文章呢有如下三个原因: * 希望在脚本中,能够以过”非阻塞”的方式获取进程cpu利 ...

  5. iis asp.net4.0注册

    asp.net4.0下载地址:https://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/do ...

  6. 如何添加使用echats地图悬浮显示内容

    /初始化绘制全国地图配置 var option = { backgroundColor: '#000', title: { text: 'Echarts3 中国地图农村金融', subtext: '三 ...

  7. C#中准确跟踪错误异常所在的文件位置方法

    准确跟踪错误异常所在的文件位置方法是在发布改文件所在的DLL时候,把对应的pdb文件也一同发布. pdb文件是:PDB全称Program Database,不知道中文翻译叫什么.相信使用过VS的人对于 ...

  8. 【Java】的四种引用的区别

    强引用:如果一个对象具有强引用,它就不会被垃圾回收器回收.即使当前内存空间不足,JVM 也不会回收它,而是抛出 OutOfMemoryError 错误,使程序异常终止.如果想中断强引用和某个对象之间的 ...

  9. lbs@node(lbs asp blog 移植到 nodejs)

    lbs@node 2018年的4月26日,我在自己的idea清单中,加上了一条"基于 nodejs 移植 lbs 博客系统". 一.lbs 是什么东东? 它是一款比较小众的博客程序 ...

  10. was设置事务超时

    select Application servers ->server1 From the Configuration tab, expand Container Services under ...