1、待排序中的元素作数组的下标或map的键值

例题:PAT甲级_1141 PAT Ranking of Institutions

#include<bits/stdc++.h>
using namespace std;
const int maxn = ; struct Node {
int personNum = ;
int scoreB = , scoreA = , scoreT = ;
int score;
}; map<string, Node> mp;
vector<string> ansSchoolName; bool cmp(string a, string b) {
if (mp[a].score != mp[b].score) return mp[a].score > mp[b].score;
else return mp[a].personNum < mp[b].personNum;
}
int main() {
int n;
scanf("%d", &n);
int score;
string id, schoolName;
for (int i = ; i < n; i++) {
cin >> id >> score >> schoolName;
transform(schoolName.begin(), schoolName.end(), schoolName.begin(), ::tolower);
mp[schoolName].personNum++;
if (id[] == 'A') mp[schoolName].scoreA += score;
else if (id[] == 'B') mp[schoolName].scoreB += score;
else mp[schoolName].scoreT += score;
}
for (auto it = mp.begin(); it != mp.end(); it++) {
ansSchoolName.push_back(it->first);
it->second.score = (int)(it->second.scoreA + it->second.scoreB / 1.5 + it->second.scoreT*1.5);
}
sort(ansSchoolName.begin(), ansSchoolName.end(), cmp);
int r = ;
printf("%d", ansSchoolName.size());
for (int i = ; i < ansSchoolName.size(); i++) {
if (i > && mp[ansSchoolName[i]].score != mp[ansSchoolName[i - ]].score) {
r = i + ;
}
printf("%d %s %d %d\n", r, ansSchoolName[i].c_str(), mp[ansSchoolName[i]].score, mp[ansSchoolName[i]].personNum);
}
return ; }

8、sort排序中比较函数的几种应用方式的更多相关文章

  1. spring 整合 mybatis 中数据源的几种配置方式

    因为spring 整合mybatis的过程中, 有好几种整合方式,尤其是数据源那块,经常看到不一样的配置方式,总感觉有点乱,所以今天有空总结下. 一.采用org.mybatis.spring.mapp ...

  2. Django中提供的6种缓存方式

    由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用: 缓存,缓存将一个某个views的返回值保存至内存或者memcache中, ...

  3. 【温故知新】——原生js中常用的四种循环方式

    一.引言 本文主要是利用一个例子,讲一下原生js中常用的四种循环方式的使用与区别: 实现效果: 在网页中弹出框输入0   网页输出“欢迎下次光临” 在网页中弹出框输入1   网页输出“查询中……” 在 ...

  4. Springboot中IDE支持两种打包方式,即jar包和war包

    Springboot中IDE支持两种打包方式,即jar包和war包 打包之前修改pom.xml中的packaging节点,改为jar或者war    在项目的根目录执行maven 命令clean pa ...

  5. JAVA高级架构师基础功:Spring中AOP的两种代理方式:动态代理和CGLIB详解

    在spring框架中使用了两种代理方式: 1.JDK自带的动态代理. 2.Spring框架自己提供的CGLIB的方式. 这两种也是Spring框架核心AOP的基础. 在详细讲解上述提到的动态代理和CG ...

  6. Vue中常用的几种传值方式

    Vue中常用的几种传值方式 1. 父传子 父传子的实现方式就是通过props属性,子组件通过props属性接收从父组件传过来的值,而父组件传值的时候使用 v-bind 将子组件中预留的变量名绑定为da ...

  7. sort排序中的坑

    问题的产生原因: 在一篇阿里面试题的跟帖中,很多人应用sort()方法对数组进行排序.看似合情合理的代码,运行结果却频频出错.为什么呢?因为很多人都忽略掉了一点,那就是sort()排序默认情况下是按A ...

  8. Android中BroadcastReceiver的两种注册方式(静态和动态)详解

    今天我们一起来探讨下安卓中BroadcastReceiver组件以及详细分析下它的两种注册方式. BroadcastReceiver也就是"广播接收者"的意思,顾名思义,它就是用来 ...

  9. JAVA中单例模式的几种实现方式

    1 线程不安全的实现方法 首先介绍java中最基本的单例模式实现方式,我们可以在一些初级的java书中看到.这种实现方法不是线程安全的,所以在项目实践中如果涉及到线程安全就不会使用这种方式.但是如果不 ...

随机推荐

  1. Linux - 7种运行级别

    目录:etc/rc.d/init.d 1. linux开机过程 2. 运行级别(0-6) 存储位置 etc/inittab,开机加载,也可以用命令init [数字]切换. # 0 - 停机(默认时为0 ...

  2. 『流畅的Python』第14章:可迭代的对象、迭代器和生成器

  3. 1)python,现在用过的,后面推出每日练习语法与深度挖掘应用

    python 1, Mac 系统自带的python路径 /System/Library/Frameworks/Python.framework/Version里面存放多个版本 可通过:启动python ...

  4. 一天一点Zynq(1)xilinx-arm-linux交叉编译链 安装总结以及资源更新

    结束了对xilinx-arm-linux交叉编译链安装后,总结一下整个过程,方便后来的研究者们,少走点弯路. 关于xilinx-arm-linux交叉编译链的安装,网上一搜一大把,可是有的资料中的资源 ...

  5. 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...

  6. Java IO编程全解(二)——传统的BIO编程

    前面讲到:Java IO编程全解(一)——Java的I/O演进之路 网络编程的基本模型是Client/Server模型,也就是两个进程之间进行相互通信,其中服务端提供位置信息(绑定的IP地址和监听端口 ...

  7. MapServer Tutorial——MapServer7.2.1教程学习(大纲)

    MapServer Tutorial——MapServer7.2.1教程学习(大纲) 前言 最近在学习Gis方面的知识,因为电脑硬件配置偏低,顾选择MapServer入手.网上搜索MapServer系 ...

  8. windows下《Go Web编程》之Go开发工具

    Go开发工具很多,比较喜欢的使用作者列出的第一个工具,LiteIDE.它是一款专门为Go语言开发的跨平台轻量级集成开发环境. 一.LiteIDE下载安装 下载地址:https://sourceforg ...

  9. [Leetcode 18]四数之和 4 Sum

    [题目] Given an array nums of n integers and an integer target, are there elements a, b, c, and d in n ...

  10. Vuejs的$watch实现原理

    大概原理如下面代码所示: class Vue { //Vue对象 constructor (options) { this.$options=options; let data = this._dat ...