POJ 2135 Rank List

来源:互联网 发布:手机实景导航软件 编辑:程序博客网 时间:2024/06/07 06:17

Description
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

题意:
先输入班级的学生人数、名字和考试次数,在输入每场考试每位同学的分数,输出截至当前考试 Li Ming在班里的排名(注意:每次考试的分数累加)
可用map来存储同学的得分情况

#include <iostream>#include <string>#include<cstdio>#include<map>using namespace std;int main(){    int N,n,i,score,max,place;    string name;    map <string,int> mymap;    map <string,int> ::iterator it;//声明一个迭代器    cin>>N;    getchar();//读入换行    for(i=0;i<N;i++)    {        getline(cin,name);    }    cin>>n;    while(n>0)    {        max=0;        place=1;//初始名次定为1        for(i=0;i<N;i++)        {            cin>>score;            getchar();//读入空格            getline(cin,name);            mymap[name]+=score;//分数累加        }        it=mymap.find("Li Ming");//迭代器指向Li Ming        max=it->second;//将Li Ming的成绩设为最大        for(it=mymap.begin();it!=mymap.end();++it)//循环所有同学的成绩        {            if(it->second>max)                place++;//若成绩大于Li Ming,则Li Ming的排名加1        }        cout<<place<<endl;        n--;    }    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 禁行如果通过了怎么办 钻戒的戒圈磨损怎么办 多肉的肉掉了怎么办 电脑自带鼠标动不了怎么办 笔记本电脑自带鼠标动不了怎么办 包包弹簧扣松了怎么办 耳钉氧化成黑色怎么办 想买点小股票玩玩要怎么办 玩具子弹打到眼睛怎么办 玩具汽车遥控器码乱了怎么办 索尼A7屏幕花了怎么办? 汽车冷冻器坏了怎么办 sim卡损坏怎么办 补卡 异或门一个输入怎么办 迷你世界加不了好友怎么办 电脑软件显示无效应用程序怎么办 美的滚筒洗衣机打不开门怎么办 手机存储卡坏了怎么办 回南天地板潮湿怎么办 lg滚筒洗衣机门打不开怎么办 西门子滚桶洗衣机门打不开怎么办 洗衣机离合器螺丝卸不动怎么办 门锁保险栓坏了怎么办 小车电瓶没电了怎么办 重装机兵战车底盘坏了怎么办 父亲沉迷安利十年该怎么办 脚的大脚骨痛怎么办 自考准考证号忘记了怎么办 有桌子老师不出马怎么办 电商遇到职业打假人怎么办 超市遇到职业打假人怎么办 阿里巴巴碰到职业打假人怎么办 商家遇到职业打假人怎么办 买过期食品不赔怎么办 淘宝卖假货遇到打假师怎么办 网店遇到职业打假人怎么办 职业打假师把我起诉法院怎么办 被职业打假举报了怎么办 车档杆拉不动显示不在p档怎么办 宜人贷还不起了怎么办 买高跟鞋一只脚合适一只脚挤怎么办