题解 | #排名#

排名

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;
}

全部评论

相关推荐

joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务