水题,竟然花了那么多时间。。。主要是不知道为什么,明明在本机上编译过去了,但是用c++提交却编译错误。。。最后用g++提交AC

题意:给出n个学生的名字,然后给出m个测验。
  每个测验给出n个学生的分数。
  当给出第i次测验的成绩,求Li Ming在所有学生中,前i次成绩总和的排名(若分数相同,则Li Ming排在第一个)

  开始没仔细看题,以为对于每次测验,只要给出Li Ming在此次测验中的排名。
  后来才知道,原来题目中有这么一句话:
  In the i-th line, you should give the rank of Li Ming after the i-th exam.
  The rank is decided by the total scores。。。

思路:用map建立映射关系,最后求名次的时候for循环一遍即可。

#include <iostream>
#include <stdio.h>
#include <map>
#include <string.h>
#include <algorithm> const int maxn=;
using namespace std;
int n,m;
int score[maxn];
map<string,int> stu; //建立学生名字到编号的映射 int main()
{
char str[];
int fenshu;
cin>>n;
getchar();
for(int i=;i<=n;i++){
gets(str); //用gets读取名字
stu[str]=i;
}
cin>>m;
memset(score,,sizeof(score));
while(m--){
for(int i=;i<=n;i++){
scanf("%d",&fenshu);
getchar(); //先读取分数后面的一个空格
gets(str);
score[stu[str]]+=fenshu;
}
int ranks=; //李明的排名
for(int i=;i<=n;i++)
if(score[i]>score[stu["Li Ming"]])
ranks++;
cout<<ranks<<endl;
}
return ;
}

POJ 2153 Rank List (map映射)的更多相关文章

  1. poj 2153 Rank List(查找,Map)

    题目链接:http://poj.org/problem?id=2153 思路分析: 判断Li Ming的成绩排名,需要在所有的数据章查找成绩比其高的人的数目,为查找问题. 查找问题可以使用Hash表, ...

  2. poj 2153 Rank List

    原题链接:http://poj.org/problem?id=2153 简单题,map,平衡树均可.. map: #include<algorithm> #include<iostr ...

  3. poj 2513(欧拉路径+字典树映射)

    题目链接:http://poj.org/problem?id=2513 思路:题目还是很简单的,就是判断是否存在欧拉路径,我们给每个单词的头和尾映射序号,统计度数.对于给定的无向图,当且仅当图连通并且 ...

  4. ZOJ 3644 Kitty's Game dfs,记忆化搜索,map映射 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4834 从点1出发,假设现在在i,点数为sta,则下一步的点数必然不能是sta的 ...

  5. POJ2503——Babelfish(map映射+string字符串)

    Babelfish DescriptionYou have just moved from Waterloo to a big city. The people here speak an incom ...

  6. map——映射(message.cpp)

    信息交换 (message.cpp) [题目描述] Byteland战火又起,农夫John派他的奶牛潜入敌国获取情报信息. Cow历尽千辛万苦终于将敌国的编码规则总结如下: 1 编码是由大写字母组成的 ...

  7. filter过滤器与map映射

    filter过滤器 >>> list(filter(None,[0,1,2,True,False])) [1, 2, True] filter的作用就是后面的数据按照前面的表达式运算 ...

  8. map映射

    采集于:https://blog.csdn.net/luanpeng825485697/article/details/78056312 映射map: var map = new Map(); //映 ...

  9. Java精选笔记_集合【Map(映射)接口】

    Map(映射)接口 简介 该集合存储键值对,一对一对的往里存,并且键是唯一的.要保证map集合中键的唯一性. 从Map集合中访问元素时,只要指定了Key,就能找到对应的Value. 关键字是以后用于检 ...

随机推荐

  1. Secondary IP Addressing

    Secondary IP Addressing secondary IP addressing. Secondary addressing uses multiple networks or subn ...

  2. uva 11186 Circum Triangle<叉积>

    链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. hdu 2034 人见人爱A-B

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2034 人见人爱A-B Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目, ...

  4. hdu 4941 Magical Forest

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4941 Magical Forest Description There is a forest can ...

  5. 记录bigdesk中ElasticSearch的性能参数

    定时采集bigdesk中的Elasticsearch性能参数,并保存到数据库或ELK,以便于进行长期监控. 基于python脚本实现,脚本如下: #coding=gbk import httplibi ...

  6. OC中的消息传递和初始化

    [receiver message]:[接收者 消息] 把消息传递给接收者. getter(接收器),setter(设置器):只设置和读取一个参数. Person *p1 = [[Person all ...

  7. WinForm GDI+自定义控件总结(一)

    前言 由于项目的原因好久没写博客了,也正是项目的原因开始系统的学习WinForm,从而接触到自定义控件的开发.自定义控件的开发有一定的难度,对开发者要求比较高,需要了解Windows运行的机制,熟悉w ...

  8. ifstat-网络接口监测工具

    ifstat-网络接口监测工具 http://gael.roualland.free.fr/ifstat/ ifstat is a tool to report network interfaces ...

  9. FPGA开发心得

    创新源于模仿,另一个意思就是,我们需要站在巨人的肩膀上起航. 至芯科技培训注重于“按图施工”,在没有达到这种境界的时候,我们需要有我们自己的思想 我的思想: always 时钟分频 数据接收 上升沿和 ...

  10. 37.altium designer中的class和rules?

    在布局布线工程中,遇到复杂工程时,难免要进行class和rules的设置,经过试验证明,class和rules的子目录是有优先级的.