29行中把string全部转成lowercase, 我记得之前写成

transform(school.begin(), school.end(), ::tolower);

是可行的,不知道为什么这次编译不过,改成下面这样才行。迷惑不解。

transform(school.begin(), school.end(), school.begin(), tolower);

整体代码如下:

#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>int N, score, cnt, rank;
std::string id, school;
std::unordered_map<std::string, int> m;struct sch{std::string schCode;double tws = 0.0;int Ns = 0;sch(std::string _str): schCode(_str){}
};std::vector<sch> res;bool cmp(const sch &a, const sch &b){return (int)a.tws != (int)b.tws ? (int)a.tws > (int)b.tws : (a.Ns != b.Ns ? a.Ns < b.Ns : a.schCode < b.schCode);
}int main(){std::cin >> N;cnt = 0;for(int i = 0; i < N; ++i){std::cin >> id >> score >> school;transform(school.begin(), school.end(), school.begin(), tolower);if(m.find(school) == m.end()){m[school] = cnt++;res.push_back(sch(school));}++res[m[school]].Ns;if(id[0] == 'B'){res[m[school]].tws += score / 1.5;}else if(id[0] == 'A'){res[m[school]].tws += score;}else{res[m[school]].tws += 1.5 * score;}}std::cout << res.size() << std::endl;sort(res.begin(), res.end(), cmp);rank = 1;std::cout << rank << " " << res[0].schCode << " " << (int)res[0].tws << " " << res[0].Ns << std::endl;for(int i = 1; i < res.size(); ++i){if((int)res[i].tws != (int)res[i - 1].tws){rank = i + 1;}std::cout << rank << " " << res[i].schCode << " " << (int)res[i].tws << " " << res[i].Ns << std::endl;}return 0;
}

题目如下:

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 (≤105), 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.

1141 PAT Ranking of Institutions (PAT甲级)相关推荐

  1. PAT甲级1141 PAT Ranking of Institutions :[C++题解]结构体、排序、哈希表、结构体构造函数、结构体内写函数、排名

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:和下面这题是一道题: PAT甲级1137 Final Grading:[C++题解]结构体.排序.哈希表.结构体构造函数.结构体内写函 ...

  2. PAT(A) - 1141. PAT Ranking of Institutions (25)

    1141. PAT Ranking of Institutions (25) 时间限制 500 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  3. 1141 PAT Ranking of Institutions (25 分)

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

  4. PAT A1141 PAT Ranking of Institutions ——昨夜西风凋碧树

    PAT A1141 PAT Ranking of Institutions 中间计算TWS时不能使用int,否则最后一个测试点不过.但是比较和输出又需要用int,在里面强转int也不给AC,无奈只好先 ...

  5. 1141. PAT Ranking of Institutions (25)

    https://github.com/uiiuiiu/PAT/blob/master/Advanced/1141%20%20Ranking%20of%20Institutions%EF%BC%8825 ...

  6. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

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

  7. PAT甲级1025 PAT Ranking:[C++题解]排序、结构体、排名

    文章目录 题目分析 题目链接 题目分析 一个区域排名和一个总排名.启发我们每个同学的数据存两份,一个存在区域数组中,另一个存在整体数组中. 有序列表中排名怎么求呢? 比如序列 得分:99 98 98 ...

  8. [PAT A1025]PAT Ranking

    [PAT A1025]PAT Ranking 题目描述 1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by th ...

  9. PAT乙级095 解码PAT准考证

    1095 解码PAT准考证 (25 分) PAT 准考证号由 4 部分组成: 第 1 位是级别,即 T 代表顶级:A 代表甲级:B 代表乙级: 第 2~4 位是考场编号,范围从 101 到 999: ...

最新文章

  1. Linux环境编译安装Mysql以及PHP中文乱码解决
  2. 安卓java读取软件自身包名,android 获取第三方应用程序包名并启动 | 学步园
  3. tkinter的函数与实例
  4. squidguard实现
  5. java 解析 csv 文件
  6. java虚拟机和javaGC_Java虚拟机(三):GC算法和种类
  7. 2016. 增量元素之间的最大差值
  8. 图形学必备!斯坦福图形学几何处理算法课程1——Surface Reconstruction
  9. [leetcode]84. Largest Rectangle in Histogram c语言
  10. 我国低轨宽带通信卫星系统建设迈出了实质性的一步
  11. 转分享[Mac] QQ音乐Mac特别版 可以下载无损
  12. xp3系统配置cocos2dx
  13. java uploadify 下载_java uploadify 实现文件上传
  14. 各省简称 拼音 缩写_近50个拼音/英文缩写合集 (一)
  15. 个人微信小程序开发入门教程:下载微信开发工具
  16. poi导出Excel,表格画斜线,并设置数据
  17. 编译--把高级语言变成低级语言
  18. 重装也无法修复此计算机,win10系统重置此电脑失败怎么解决
  19. scandisk.exe 流氓软件的删除
  20. Fiddler的入门使用

热门文章

  1. 树莓派4B安装nodejs,noble
  2. Android开发-优秀博客参考
  3. 上市公司股利政策数据( 2000-2020年)
  4. Unsupervised Night Image Enhancement: When Layer Decomposition Meets Light-Effects Suppression论文阅读笔记
  5. chm文件打不开解决方法
  6. 【打卡第241道】【动态规划DP01背包】【leetCode高频】:1049. 最后一块石头的重量 II
  7. html超链接自动跳转,超链接是什么(一打开网页就跳转另一个网站)
  8. 预告:达·芬奇密码全球首映!
  9. 笔记本电脑没有声音怎么办?5个必会方法分享
  10. 排序算法的实现。用C语言编程实现冒泡排序、选择排序、插入排序、shell排序、快速排序、堆排序算法、归并排序。利用随机函数产生N个随机整数(10000以上)。