【PTA】 L2-027 Hall of Fame and Voucher (25 points) 【Structure order】

For students studying the "Data Structure" course at the Chinese University MOOC (http://www.icourse163.org/), if you want to obtain a certificate, the total evaluation score must reach 60 points or more, and there are additional benefits: total Those who score in the range of [G, 100] can get a PAT voucher of 50 yuan; those who are in the range of [60, G) can get a PAT voucher of 20 yuan. The test centers are universal and valid for one year. At the same time, the teacher will also include the top K students in the overall assessment score in the course "Hall of Fame". For this question, please write a program to help the teacher list the students in the Hall of Fame and count the total number of PAT vouchers issued.

Input format:
Enter 3 integers in the first line, which are N (a positive integer not exceeding 10 000, which is the total number of students), G (an integer in the interval (60,100), which is the voucher described in the title) Grade dividing line), K (a positive integer not exceeding 100 and not exceeding N, which is the lowest rank to enter the Hall of Fame). In the next N lines, each line gives a student's account number (a string of no more than 15 digits and no spaces) and a total evaluation score (an integer in the interval [0, 100]), separated by spaces. The title guarantees that there are no duplicate accounts.

Output format:
First output the total face value of the issued PAT vouchers in one line. Then output the ranking, account number, and results of the students who entered the Hall of Fame in non-ascending order of the overall evaluation results, separated by a space. It should be noted that students with the same grades enjoy a tied ranking. When the rankings are tied, they will be output in ascending alphabetical order of their account numbers.

Input sample:

10 80 5
cy@zju.edu.cn 78
cy@pat-edu.com 87
1001@qq.com 65
uh-oh@163.com 96
test@126.com 39
anyone@qq.com 87
zoe@mit.edu 80
jack@ucla.edu 88
bob@cmu.edu 80
ken@163.com 70

Sample output:

360
1 uh-oh@163.com 96
2 jack@ucla.edu 88
3 anyone@qq.com 87
3 cy@pat-edu.com 87
5 bob@cmu.edu 80
5 zoe@mit.edu 80

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,g,k,sum=0,cnt=0,flag=0,id=1;
vector<int> ans;

struct node{
    
    
	string s;
	int score;
}peo[10050];

bool cmp(node a,node b){
    
     //分数不同从大到小,分数相同账号从小到大
	if(a.score!=b.score) return a.score>b.score; 
	else return a.s<b.s;
}

int main()
{
    
    	    
	cin>>n>>g>>k;
	for(int i=0;i<n;i++)
		cin>>peo[i].s>>peo[i].score;
	
	sort(peo,peo+n,cmp); 
	
	int flag=0;
	for(int i=0;i<n;i++)
	{
    
    
		if(peo[i].score>=g && peo[i].score<=100) sum+=50;
		else if(peo[i].score>=60 && peo[i].score<g) sum+=20;
		
		if(!flag) ans.push_back(i);
		if(i>=k && i+1<n && peo[i+1].score!=peo[i].score) flag=1; 
		//已经排了k名,并且下一个不与当前分数一样才标记(可能有多个第k名),标记后不再进入名人堂
	}
	
	cout<<sum<<endl;
	int l=0;
	for(int i=0;i<ans.size();i++)
	{
    
    
		if(i>0 && peo[i].score!=peo[i-1].score) //分数不同,id
		{
    
    
			id=id+l+1; //跳过连续相同的排名
			l=0; 
		} 
		else if(peo[i].score==peo[i-1].score) l++; //l记录连续相同分数的个数
		cout<<id<<" "<<peo[i].s<<" "<<peo[i].score<<endl;
	}
		
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45260385/article/details/109788839