题解 | #排名#

排名

https://www.nowcoder.com/practice/f7c80167c5b04fd2ac4b6d7080a73f01

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

const int MAXN = 10 + 10;
const int MAXM = 1000 + 10;

int arr[MAXN];//题目

struct Student {
	string id;
	int score;
};

Student student[MAXM];

bool Compare (Student x, Student y){
	if (x.score != y.score){
		return x.score > y.score;
	}else{
		return x.id < y.id;
	}
	return false;	
}

int main(){
	int n, m, g;
	while(cin >> n){
		if (n == 0){
			break;
		}
		cin >> m >> g;		
		for (int i = 1; i <= m; i++){
			cin >> arr[i];
		}
		for (int i = 0; i < n; i++){
			int tihao, finishNum;
			int sum = 0;
			cin >> student[i].id >> finishNum;
			for (int j = 1; j <= finishNum; j++){
				cin >> tihao;
				sum += arr[tihao];
			}
            student[i].score = sum;
		}
		sort(student, student + n, Compare);
			int k = 0;
			for (int i = 0; i < n; i++){
				if (student[i].score >= g){
					k++;
				}else{
					break;
				}
			}
			cout << k << endl;
			for (int i = 0; i < k; i++){
				cout << student[i].id << " " << student[i].score << endl;
			} 
	}	
	return 0;
}

全部评论

相关推荐

码农索隆:单休一个月少休息4天,一年就是48天,平时节假日,别人3天假期,单休的两天
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-29 20:12
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务