hhhqzh


私信TA

用户名:hhhqzh

访问量:1857

签 名:

等  级
排  名 2574
经  验 2150
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校 scnu
专  业

  自我简介:

解题思路:
我用了map来解,先是输入姓名name把map[name]都初始化为0。之后输入分数则把分数累加,输入一次考试成绩后则与DaDa的成绩进行比较,比DaDa大则DaDa的排名加一之后输出。

注意事项:
排名指的是当前所有考试分数的排名而不是一门考试的排名
参考代码:

#include <iostream>
#include <string>
#include <string.h>
#include <map>
using namespace std;


int main()
{
	map <string,int> score;
	int n,m,i;
	cin>>n;
	string *str = new string[n];
	for(i=0;i<n;i++){
		cin>>str[i];
		score[str[i]]=0;
	}
	cin>>m;
	while(m>0){
		int x;
		for(i=0;i<n;i++){
			string name;
			int s;
			cin>>s>>name;
			score[name] += s;
			if(name == "DaDa")
				x=score[name];
		}
		int q=1;///排名
		for (map<string, int>::iterator iter = score.begin();iter!=score.end(); iter++) {
			if(iter->first!="DaDa"){
				if(iter->second > x)
					q++;
			}
		}
		cout<<q<<endl;
		m--;
	}
	return 0;
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区