Rank List(map)

 题意:首先给出一个整数n表示班级的学生人数,然后是学生名字,之后给出一整数m,表示考试次数,下面每行是每次考试学生的分数和名字,最后输出每次考试李明的排名,排名由总分决定。

思路:定义一个map,存入每次考试学生的成绩和名字,由于排名由每次考试的分数总和决定,所以map最后是用分数总和与李明的成绩进行比较,最后输出李明的排名即可,注意要吸收空格。

Li Ming is a good student. He always asks the teacher about his rank in his class after every exam, which makes the teacher very tired. So the teacher gives him the scores of all the student in his class and asked him to get his rank by himself. However, he has so many classmates, and he can’t know his rank easily. So he tends to you for help, can you help him?

Input

The first line of the input contains an integer N (1 <= N <= 10000), which represents the number of student in Li Ming’s class. Then come N lines. Each line contains a name, which has no more than 30 letters. These names represent all the students in Li Ming’s class and you can assume that the names are different from each other.

In (N+2)-th line, you'll get an integer M (1 <= M <= 50), which represents the number of exams. The following M parts each represent an exam. Each exam has N lines. In each line, there is a positive integer S, which is no more then 100, and a name P, which must occur in the name list described above. It means that in this exam student P gains S scores. It’s confirmed that all the names in the name list will appear in an exam.

Output

The output contains M lines. 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. If Li Ming has the same score with others, he will always in front of others in the rank list.

Sample Input

3
Li Ming
A
B
2
49 Li Ming
49 A
48 B
80 A
85 B
83 Li Ming

Sample Output

1
2

AC代码 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#include<string> 
using namespace std;
map<string,int>m;
map<string,int>::iterator it;		//迭代器
int main()
{
	int i,n,t,k;
	char s[10010];
	cin>>n;
	getchar();
	for(i=1;i<=n;i++)
	{
		gets(s);
		m[s]=0;				//相当于初始化map数组 
	}
	cin>>t;
	while(t--)
	{
		int num=1;
		for(i=1;i<=n;i++)
		{
			cin>>k;
			getchar();
			gets(s);
			m[s]+=k;		//题目要求是分数总和排名 
		}
		for(it=m.begin();it!=m.end();it++)
		{
			if((*it).second>m["Li Ming"])			//分别让每个同学的成绩和李明比较 
				num++;								//计算李明的排名 
		}
		cout<<num<<endl;
	}
	return 0;
} 

努力努力再努力

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ACM/ICPC比赛成绩会按照一定的规则计算各位参赛者的名次并实时显示排行榜,计算规则主要参考解题的数量及罚时,解题数量越多,罚时越少,则排名越高。 解题数量很容易计算,只需考察比赛中标记为“Accepted”的题数即可。罚时计算则相对复杂,对于提交到竞赛系统中的每道题目,系统会给出一个罚时,为从比赛开始到该题提交的代码第一次被“Accepted”的时间。请注意,只是第一次“Accepted”。对于“Accepted”之前的每次提交,都有20分钟的罚时,但如果该题目最终未解出,则不计罚时。 先在有一个比赛的题目通过情况记录,请生成该比赛的排行榜。 示例输入: 2008-04-25 18:00:00 2008-04-25 23:30:00 1000 1001 1002 1003 1004 38 602203621 1002 Accepted 756K 30MS C++ 2008-04-25 18:04:59 37 liheyuan 1002 Wrong_Answer 768K 10MS C++ 2008-04-25 18:28:05 36 ftest 1000 Accepted 888K 10MS C++ 2008-04-25 21:30:32 35 ftest 1000 Accepted 904K 10MS C++ 2008-04-25 21:30:55 34 gaojianwei 1000 Accepted 768K 10MS C 2008-04-25 22:15:58 33 gaojianwei 1001 Wrong_Answer 904K 10MS C 2008-04-25 22:18:01 32 gaojianwei 1004 Accepted 768K 10MS C 2008-04-25 22:24:23 31 lzz 1000 Accepted 904K 10MS C++ 2008-04-25 23:29:27 30 lzz 1001 Wrong_Answer 904K 10MS C++ 2008-04-25 23:30:17 示例输出: Rank Name Solved 1000 1001 1002 1003 1004 Penalty 1 gaojianwei 2 4:15:58 -1 0 0 4:24:23 8:40:21 2 602203621 1 0 0 0:04:59 0 0 0:04:59 3 ftest 1 3:30:32 0 0 0 0 3:30:32 4 lzz 1 5:29:27 0 0 0 0 5:29:27 5 liheyuan 0 0 0 -1 0 0 0:00:00

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值