题目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. grid - 网格项目层级

    网格项目可以具有层级和堆栈,必要时可能通过z-index属性来指定. 1.在这个例子中,item1和item2的开始行都是1,item1列的开始是1,item2列的开始是2,并且它们都跨越两列.两个网 ...

  2. Effective Java 第三版—— 85. 其他替代方式优于Java本身序列化

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  3. Effective Java 第三版——70. 对可恢复条件使用检查异常,对编程错误使用运行时异常

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  4. 您还差宝贝一张语文教学光盘!教你如何制作ISO文件

    1 大家没有发现 宝宝初上小学无法专心地做作业.读书? 我家的宝贝就是这样 做作业时 总是东搞搞,西弄弄 完全无法专心 再不就是不耐心 读一遍课本就觉得累 读三两遍就说学习是个苦差事儿 2 一直以来 ...

  5. 【20180409】IT管理之IT十二条令

    团队越来越大,靠人管几乎有力无心,只能靠制度管理了. 前段时间对部门颁布了12条令,效果明显. 特此Mark. 汇报: 三条总结:汇报讲究精简,一个事情最多一句话概括. 一页报告:内容精简,报告一页w ...

  6. zc702-自定义AXI-IP核实验

    目的: 自定义一个IP核,通过AXI总线与ARM系统连接 环境: Win7 32bit Vivado2014.4.1 Xilinx sdk2014.4 开发板: Zc702 第一步: 新建一个自定义的 ...

  7. 【转】Android系统开篇

    版权声明:本站所有博文内容均为原创,转载请务必注明作者与原文链接,且不得篡改原文内容.另外,未经授权文章不得用于任何商业目的. 一.引言 Android系统非常庞大.错综复杂,其底层是采用Linux作 ...

  8. IOS-企业开发人员账号&amp;邓白氏码申请记录

    Apple开发人员账号分三种,个人.公司,还有企业.个人和公司都称为标准账号. 另一种是教育机构的账号. 账号介绍 个人和公司的就不说了.如今仅仅说企业账号 首先是申请企业账号的地址: https:/ ...

  9. C语言 · 礼物盒

    礼物盒 分值: 20 小y 有一个宽度为 100cm,高度为 20cm,深度为 1cm 的柜子,如下图. 小y 还有 36 个礼物盒,他们的深度都为 1cm. 他们对应的宽度和高度如下,单位(cm). ...

  10. 优化实现Mobile/Bumped Diffuse

    在上一篇帖子的基础上增加一张法线贴图即可: Shader "James/Scene/Bumped_Diffuse" { Properties { _MainTex ("B ...