L2-3 名人堂与代金券 (25 分)

L2-3 名人堂与代金券 (25 分)
对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,总评成绩必须达到 60 分及以上,并且有另加福利:总评分在 [G, 100] 区间内者,可以得到 50 元 PAT 代金券;在 [60, G) 区间内者,可以得到 20 元PAT代金券。全国考点通用,一年有效。同时任课老师还会把总评成绩前 K 名的学生列入课程“名人堂”。本题就请你编写程序,帮助老师列出名人堂的学生,并统计一共发出了面值多少元的 PAT 代金券。

输入格式:
输入在第一行给出 3 个整数,分别是 N(不超过 10 000 的正整数,为学生总数)、G(在 (60,100) 区间内的整数,为题面中描述的代金券等级分界线)、K(不超过 100 且不超过 N 的正整数,为进入名人堂的最低名次)。接下来 N 行,每行给出一位学生的账号(长度不超过15位、不带空格的字符串)和总评成绩(区间 [0, 100] 内的整数),其间以空格分隔。题目保证没有重复的账号。

输出格式:
首先在一行中输出发出的 PAT 代金券的总面值。然后按总评成绩非升序输出进入名人堂的学生的名次、账号和成绩,其间以 1 个空格分隔。需要注意的是:成绩相同的学生享有并列的排名,排名并列时,按账号的字母序升序输出。

输入样例:
10 80 5
[email protected] 78
[email protected] 87
[email protected] 65
[email protected] 96
[email protected] 39
[email protected] 87
[email protected] 80
[email protected] 88
[email protected] 80
[email protected] 70
输出样例:
360
1 [email protected] 96
2 [email protected] 88
3 [email protected] 87
3 [email protected] 87
5 [email protected] 80
5 [email protected] 80
本题就是一个简单的sort排序 细节要注意分数一样时 要对字符串进行字典序排序

#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;
struct stu{
	string yx;
	int score;
	int pm;
}s[10002];
int cmp(stu a,stu b)
{
	if(a.score==b.score)
	{
		if(a.yx>b.yx)
		{
			return 0;
		} 
		else
		{
			return 1;
		}
	}
	else
	{
		return a.score>b.score;
	}
}
int main(){
int n,m,t;
int sum=0;
cin>>m>>n>>t;
s[m+1].score=166;
for(int i=0;i<m;i++){
	cin>>s[i].yx;
	cin>>s[i].score;
}
sort(s,s+m,cmp);
//cout<<" "<<s[3].yx<<" "<<s[3].score<<endl;
for(int i=0;i<m;i++){
	if(s[i].score>=n){
		sum=sum+50;
	}
	if(s[i].score>=60&&s[i].score<n){
		sum=sum+20;
	}
}
cout<<sum<<endl;
int v=1,v1=1,i1;
for(i1=0;i1<m;i1++){
		s[i1].pm=v;
		v++;
}
for(i1=1;i1<m;i1++){
	if(s[i1].score==s[i1-1].score){
v1=s[i1-1].pm;
s[i1].pm=v1;
	}
}

for(int i=0;i<m;i++){
	if(s[i].pm<=t){
		cout<<s[i].pm<<" "<<s[i].yx<<" "<<s[i].score<<endl;
	}
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/Stydwn/article/details/87969917