PAT_A1141#PAT Ranking of Institutions
Source:
Description:
After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where
ID
is a string of 6 characters with the first one representing the test level:B
stands for the basic level,A
the advanced level andT
the top level;Score
is an integer in [0, 100]; andSchool
is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed thatID
is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where
Rank
is the rank (start from 1) of the institution;School
is the institution code (all in lower case); ;TWS
is the total weighted score which is defined to be the integer part ofScoreB/1.5 + ScoreA + ScoreT*1.5
, whereScoreX
is the total score of the testees belong to this institution on levelX
; andNs
is the total number of testees who belong to this institution.The institutions are ranked according to their
TWS
. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order ofNs
. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
Sample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
Keys:
- map(C++ STL)
- string(C++ STL)
- 快乐模拟
Attention:
- 字符串转换为小写:transform(s.begin(),s.end(),s.begin(),::tolower);
- 字符串转换为大写:transform(s.begin(),s.end(),s.begin(),::toupper);
- 分数用double存储,比较总分时再取整数部分,若计算各个Int再相加,会有误差
- cmp,rank,printf,三处的比分都要用整数,各对应一个测试点
Code:
/*
Data: 2019-08-06 20:19:45
Problem: PAT_A1141#PAT Ranking of Institutions
AC: 33:40 题目大意:
按分数排名
输入:
第一行给出,考试人数N<=1e5
接下来N行给出,ID(1位字母+5位数字),分数[0,100],学校(<=6,大小写敏感)
输出:
第一行输出,学校总数M
接下来M行,排名(>=1), 学校(小写),总分(B/1.5+A+T*1.5),考生数
排序规则,总分递减,人数递增,学校字典序
*/
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1e5+;
int pos=;
map<string,int> mp;
struct node
{
string sch;
double score;
int num;
}ans[M]; int Hash(string s)
{
if(mp[s]==)
{
ans[pos]=node{s,,};
mp[s]=pos++;
}
return mp[s];
} bool cmp(const node &a, const node &b)
{
if((int)a.score != (int)b.score)
return a.score > b.score;
else if(a.num != b.num)
return a.num < b.num;
else
return a.sch < b.sch;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n;
scanf("%d", &n);
for(int i=; i<n; i++)
{
string id,sc;
double grade;
cin >> id >> grade >> sc;
transform(sc.begin(),sc.end(),sc.begin(),::tolower);
int pt = Hash(sc);
if(id[]=='T') grade *= 1.5;
if(id[]=='B') grade /= 1.5;
ans[pt].score += grade;
ans[pt].num++;
}
sort(ans+,ans+pos,cmp);
int r=;
printf("%d\n", pos-);
for(int i=; i<pos; i++)
{
if(i!= && (int)ans[i-].score != (int)ans[i].score)
r=i;
printf("%d %s %d %d\n", r,ans[i].sch.c_str(),(int)ans[i].score,ans[i].num);
} return ;
}
PAT_A1141#PAT Ranking of Institutions的更多相关文章
- 1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...
- 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 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- [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 ...
- 1141 PAT Ranking of Institutions
题意:给出考生id(分为乙级.甲级和顶级),取得的分数和所属学校.计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数.最后对学校进行排名. 思路:本题的研究对象是学校,而不是考生!因此,建立学 ...
- PAT Ranking (排名)
PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...
随机推荐
- POJ 3252 Round Numbers 组合数学
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13381 Accepted: 5208 Description The ...
- cogs 7. 通信线路
7. 通信线路 ★★ 输入文件:mcst.in 输出文件:mcst.out 简单对比时间限制:1.5 s 内存限制:128 MB 问题描述 假设要在n个城市之间建立通信联络网,则连通n ...
- MySQL:解决MySQL无法启动的问题
MySQL无法启动的原因有多种,这里是我遇到的一种情况和解决方法. 起因: 最近项目需要使用MySQL,于是想在MAC上安装一个本地的数据库,但是其实忘了已经安装过一个版本了,结果发现新的服务器怎么也 ...
- C语言实现的lisp解析器介绍
近期.由于Perl而学习函数式编程, 再进一步学习lisp, 真是一学习就发现自己的渺小. 无意中找到了一个很easy的C语言版的, lisp解析器. 代码非常短, 却非常见功底, 涨姿势了. 附带还 ...
- WINDOWS下配置SVN代码管理
服务器端使用 visualsvn server,客户端使用tortoiseSvn. 一.服务器端 1.首先,下载visualsvn server,安装到服务器.下载地址: http://www.vis ...
- BZOJ 2440 中山市选2011 全然平方数 二分答案+容斥原理+莫比乌斯反演
题目大意:求第k个无平方因子数是多少(无视原题干.1也是全然平方数那岂不是一个数也送不出去了? 无平方因子数(square-free number),即质因数分解之后全部质因数的次数都为1的数 首先二 ...
- 循环遍历Java字符串字符的规范方法——类似python for ch in string
比如我将string作为CNN 文本处理输入: float [] input = new float[maxLength]; // 1 sentence by maxLenWords // int[] ...
- Java执行定时任务
一.用java.util.Timer 使用JAVA类Timer可实现简单的延迟和周期性任务,其中的任务使用java.util.TimerTask表示.任务的执行方式有两种: 按固定速率执行:即sche ...
- codeforces round #424 div2
A 暴力查询,分三段查就可以了 #include<bits/stdc++.h> using namespace std; ; int n, pos; int a[N]; int main( ...
- bzoj1030 文本生成器(AC自动机+dp)
1030: [JSOI2007]文本生成器 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4777 Solved: 1986[Submit][Stat ...