Source:

PAT A1141 PAT Ranking of Institutions (25 分)

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 and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID 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 of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns 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 of Ns. 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的更多相关文章

  1. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

  2. A1141. PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  3. PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  4. PAT 甲级 1141 PAT Ranking of Institutions

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...

  5. [PAT] 1141 PAT Ranking of Institutions(25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  6. 1141 PAT Ranking of Institutions (25 分)

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  7. PAT 1141 PAT Ranking of Institutions

    After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...

  8. 1141 PAT Ranking of Institutions

    题意:给出考生id(分为乙级.甲级和顶级),取得的分数和所属学校.计算各个学校的所有考生的带权总成绩,以及各个学校的考生人数.最后对学校进行排名. 思路:本题的研究对象是学校,而不是考生!因此,建立学 ...

  9. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

随机推荐

  1. http-runtime属性

    配置httpRuntime也可以让FileUpload上传更大的文件,不过设置太大了会因用户将大量文件传递到该服务器而导致的拒绝服务攻击(属性有说明) 属性 属性 选项 说明 appRequestQu ...

  2. cogs 259. 亲戚

    259. 亲戚 ★   输入文件:relations.in   输出文件:relations.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]     或许你并不知道,你 ...

  3. poj 1837 Balance (0 1 背包)

    Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10326   Accepted: 6393 题意:给你n个挂 ...

  4. MySql解压版使用

    1.解压 2.配置环境变量 3.新建空目录data,修改ini配置文件,修改basedir和datadir 4.管理员运行cmd,进入bin目录 5.mysql -install,如果提示错误,先my ...

  5. IIS发布后出现“如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题”错误

    VS2010运行程序没有任何问题,但是发布到IIS以后,连接数据库时报错:“尝试加载 Oracle 客户端库时引发 BadImageFormatException.如果在安装 32 位 Oracle ...

  6. 【九章算法免费讲座第一期】转专业找CS工作的“打狗棒法”

    讲座时间: 美西时间6月5日18:30-20:00(周五) 北京时间6月6日09:30-11:00(周六a.m) 讲座安排: 免费在线直播讲座 报名网址: http://t.cn/R2XgMSH,或猛 ...

  7. android graphic(15)—fence

    为何须要fence fence怎样使用 软件实现的opengl 硬件实现的opengl 上层使用canvas画图 上层使用opengl画图 下层合成 updateTexImage doComposeS ...

  8. 【数据结构】链式向前星知识点&代码

    代码: struct NODE{ int to; int nxt; int c; }node[MM];//链式向前星 ; void add(int a,int b,int c){ node[lcnt] ...

  9. bzoj 1059 [ ZJOI 2007 ] 矩阵游戏 —— 二分图匹配

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1059 每一列选出一个占据一行才可以: 挫败. 代码如下: #include<iostr ...

  10. easyui+struts2:datagrid无法不能得到数据

    转自:https://bbs.csdn.net/topics/390980437 easyui+struts2:datagrid无法访问到指定action: userlist.jsp部分代码: XML ...