题目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. Win10一直弹出 用户账户控制 解决

    目录 问题 解决方法一 将appwiz.cpl加入UAC白名单 解决方法二 问题 自从更新了Windows后,就出现了一个问题,隔一段时间就弹出一次下面的对话框,而且如果时间稍长,会弹出多个. 解决方 ...

  2. NOIP2010普及组 三国游戏

    题目OJ地址 http://codevs.cn/problem/1129/ https://www.luogu.org/problemnew/show/P1199 题目描述 Description 小 ...

  3. linux中Ctrl+D,Ctrl+Z,Ctrl+C

    1.用stty -a查看控制字符的终端配置 2. ctrl-c 是发送 SIGINT 信号.终止一个进程 ctrl-z 是发送 SIGSTOP信号,挂起一个进程;命令fg唤回进程. ctrl-d 不是 ...

  4. 用交叉验证改善模型的预测表现-着重k重交叉验证

    机器学习技术在应用之前使用“训练+检验”的模式(通常被称作”交叉验证“). 预测模型为何无法保持稳定? 让我们通过以下几幅图来理解这个问题: 此处我们试图找到尺寸(size)和价格(price)的关系 ...

  5. Servlet中的request对象、重定向和转发的差别(6)

    1.这里所说的request对象指的是HttpServletRequest对象,它代表client的请求,当client通过HTTP协议訪问server时.HTTP请求头中的全部信息都封装在这个对象中 ...

  6. Java之收集很好的Java学习资料地址+博客

    https://blog.insanecoder.top/tcp-packet-splice-and-split-issue/ http://blog.csdn.net/qilixiang012/ar ...

  7. 使用viewport中的vm来适配移动端页面

    前言 作为一个小前端,经常要和H5打交道,这就面临着不同终端的适配问题. Flexible方案通过Hack手段来根据设备的dpr值相应改变<meta>标签中viewport的值,给我更贴切 ...

  8. python 信息同时输出到控制台与文件

    python编程中,往往需要将结果用print等输出,如果希望输出既可以显示到IDE的屏幕上,也能存到文件中(如txt)中,该怎么办呢? 方法1 可通过日志logging模块输出信息到文件或屏幕.但可 ...

  9. 自定义命令杀死 java 进程 alias kjava

    alias kjava='ps -ef|grep ProcessName |awk "{print $2}"|xargs kill -9' 上面脚本放在杀JAVA进程中,会出现一些 ...

  10. maven添加jetty插件,同时运行多个实例

    <plugins> <!-- jetty插件 --> <plugin> <groupId>org.eclipse.jetty</groupId&g ...