名人堂與代金券 (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

#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
struct student{
	string name;
	int age;
}v[10005];
int n,g,k,ans,age=-1,z;
bool cmp(student x,student y){
	if(x.age!=y.age)
	return x.age>y.age;
	return x.name<y.name;
}
int find(int m){
	if(m>=g&&m<=100)
	return 50;
	else if(m>=60&&m<g)
	return 20;
	else
	return 0;
}
int main()
{
    scanf("%d %d %d",&n,&g,&k);
    for(int i=0;i<n;i++){
    	cin>>v[i].name>>v[i].age;
    	ans+=find(v[i].age);
	}
	sort(v,v+n,cmp);
	printf("%d\n",ans);
	for(int i=0;i<n;i++){
		if(v[i].age!=age){
			age=v[i].age;
			z=i+1;
			if(i+1<=k)
			cout<<i+1<<" "<<v[i].name<<" "<<v[i].age<<endl;
			
		}
		else{
			age=v[i].age;
			if(z<=k)
			cout<<z<<" "<<v[i].name<<" "<<v[i].age<<endl;
		}
	}
	return 0;
 } 
發佈了105 篇原創文章 · 獲贊 117 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章