PAT甲级1141 Ranking of Institutions
题目: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的更多相关文章
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- 1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- 1141 PAT Ranking of Institutions (25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1141 PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- A1141. PAT Ranking of Institutions
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
随机推荐
- 离线环境下安装ansible,借助有网环境下pip工具
环境 有网的机器(192.168.19.222):rhe65,python2.7.13,pip9.0.1 离线机器(192.168.19.203):rhe65,python2.6 FTP(192.16 ...
- java幂等性的解决方案
一.幂等性概念 在编程中.一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同.幂等函数,或幂等方法,是指可以使用相同参数重复执行,并能获得相同结果的函数.这些函数不会影响系统状态,也 ...
- [转]Jsoup(一)Jsoup详解(官方)
原文地址:http://www.cnblogs.com/zhangyinhua/p/8037599.html 一.Jsoup概述 1.1.简介 jsoup 是一款Java 的HTML解析器,可 ...
- VMware Workstation 14.1.1 精简特别版
VMware Workstation 精简特别版,由卡饭网友のcuiplay精简制作,集成许可证密钥安装即永久激活,该特别版最大特色可安装MAC OS X客户操作系统,此外添加了DELL SLIC 2 ...
- java maven 编译文件时 有些类型文件 不存在
在pom.xml中添加如下: <build> <resources> <resource> <directory>src/main/resource&l ...
- linux清理日志脚本
1.删除日志的命令 find 目录路径 -mtime +天数 -name "文件名" -exec rm -rf {} \; 例如:#!/bin/bash find /usr/loc ...
- HTTP 05 安全
TCP 打包时加密, 报文传输时 加密 通过证书来判断是否是可以访问的客户端/服务器. 公开秘钥 进行加密, 随便被人知道 私有秘钥 进行解密, 自己保留 http + 加密 + 认证 + 完整性保护 ...
- 解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";
解决方案: https://blog.csdn.net/HeatDeath/article/details/79065872 https://blog.csdn.net/hjf161105/artic ...
- c++中常用的泛型算法
std中定义了很好几种顺序容器,它们自身也提供了一些操作,但是还有很多算法,容器本身没有提供. 而在algorithm头文件中,提供了许多算法,适用了大多数顺序容器.与c++11相比,很多函数在 c+ ...
- yii2 緩存
1.Yii框架的缓存 主要就是“memcache” 和 “cache”两种 Yii的自带缓存都继承CCache 类, 在使用上基本没有区别 2.使用方法 (1)在config配置文件main.php文 ...