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 ...
随机推荐
- 招中高级web开发工程师
>>招中高级web开发工程师
- 数组去重Demo引出的思考
package com.pers.Stream; import java.util.*; import java.util.stream.Collectors; import java.util.st ...
- R文本挖掘之jiebaR包
library(jiebaRD)library(jiebaR) ##调入分词的库cutter <- worker()mydata =read.csv(file.choose(),fileEnc ...
- 城市经纬度 json 理解SignalR Main(string[] args)之args传递的几种方式 串口编程之端口 多线程详细介绍 递归一个List<T>,可自己根据需要改造为通用型。 Sql 优化解决方案
城市经纬度 json https://www.cnblogs.com/innershare/p/10723968.html 理解SignalR ASP .NET SignalR 是一个ASP .NET ...
- [转]:Delphi XE中泛型数组的使用范例
Delphi XE中泛型数组的使用范例,下面的范例简单的使用了泛型字符串数组,如用 TArray 代替 array of Word, 还可以使用 TArray 类提供的算法(就是少了点). uses ...
- 如何保持github的fork于主干同步
step1: https://help.github.com/articles/configuring-a-remote-for-a-fork/ step2: https://help.github. ...
- [20180312]进程管理其中的SQL Server进程占用内存远远大于SQL server内部统计出来的内存
sql server 统计出来的内存,不管是这个,还是dbcc memorystatus,和进程管理器中内存差距很大,差不多有70G的差异. 具体原因不止,可能是内存泄漏,目前只能通过重启服务解决 ...
- C#学习笔记(36)——事件传值(非常牛逼!)
说明(2018-4-9 23:01:20): 1. 这个真的想了很久,从晚上八点半写完上一篇博客,一直想到现在11点,以为没有办法实现了,结果看到一篇CSDN的文章,虽然没有看明白,但是看到一行代码后 ...
- 具体解释MVP矩阵之ViewMatrix
矩阵推导 ViewMatrix用于直接将World坐标系下的坐标转换到Camera坐标系下.已知相机的坐标系.还有相机在世界空间下的坐标.就能够求出ViewMatrix.以下进行具体推导. 令UVN为 ...
- myeclipse中的项目 如何在项目视窗中显示setting,classpath等配置文件
导入了别人的项目,各种jar包都放好后,path也都build好了,项目也能正常启动,但是就是项目名有红叉,这是为什么呢? 网上有人说Java build path中的jar包missing了,这是一 ...