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. [bzoj3747][POI2015]Kinoman_线段树

    Kinoman bzoj-3747 POI-2015 题目大意:有m部电影,第i部电影的好看值为w[i].现在放了n天电影,请你选择一段区间l~r使得l到r之间的好看值总和最大.特别地,如果同一种电影 ...

  2. ZooKeeper可视化Web管理工具收集(待实践)

    原来ZooKeeper是有Web管理后台的.但是仅限于操作ZooKeeper的数据,如果要监控性能,估计要借助Nagios去配合. 这些工具应该ZK UI最好用,下面是收集的一些工具安装教程: htt ...

  3. java枚举怎么用的

    package com.pingan.property.icore.pap.common.constants; /** * */public enum UMAuthStatusEnum impleme ...

  4. 使用python获取CPU和内存信息的思路与实现(linux系统)

    linux里一切皆为文件,在linux/unix的根文件夹下,有个/proc文件夹,这个/proc 是一种内核和内核模块用来向进程(process)发送信息的机制(所以叫做"/proc&qu ...

  5. Android学习笔记之:android更新ui的几种经常用法

    Android主线程不能运行耗时操作.我们通常是在子线程中运行耗时操作, 我们在运行完耗时操作后,我们一般能够通过下面几种方式来实现ui界面的更新. 首先是布局文件: <LinearLayout ...

  6. ExtJs--06--Ext.WindowGroup相关方法简单使用

    Ext.onReady(function(){ //用windowGroup对象去操作多个window窗体 var winG = new Ext.WindowGroup(); for (var i = ...

  7. SpringMVC + hibernate 配置文件

    web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="htt ...

  8. 的Linq未提交之前插入/修改时重新查询不准确问题

    来园子已经两年了,每次都是看,这次咱也写一次. 说一下今天遇到的Linq问题: 每一次插入流水表时,都需要查找表中最大的流水号+1,并且将该流水号返回,但是在同一个SubmitChange之内插入多条 ...

  9. hibernate初步

    Hibernate开发步骤1.新创建工程并且导入相关的包 主要是hibernate.mysql相关的JAR包. 注意:新导入的hibernate相关的JAR包是否与你当前所使用的jdk版本是否兼容,且 ...

  10. 判断文件是否为空 C++

    #include <sys/stat.h> int stat(const char *restrict pathname, struct stat *restrict buf); stru ...