天天看點

PTA-乙級 1080 MOOC期終成績 (測試點4)PTA-乙級 1080 MOOC期終成績 (測試點4)

PTA-乙級 1080 MOOC期終成績 (測試點4)

對于在中國大學MOOC(http://www.icourse163.org/ )學習“資料結構”課程的學生,想要獲得一張合格證書,必須首先獲得不少于200分的線上程式設計作業分,然後總評獲得不少于60分(滿分100)。總評成績的計算公式為 G=(Gmid−term×40%+Gfinal×60%),如果 Gmid−term>Gfinal;否則總評 G 就是 Gfinal。這裡 Gmid−term 和Gfinal分别為學生的期中和期末成績。

現在的問題是,每次考試都産生一張獨立的成績單。本題就請你編寫程式,把不同的成績單合為一張。

輸入格式:

輸入在第一行給出3個整數,分别是 P(做了線上程式設計作業的學生數)、M(參加了期中考試的學生數)、N(參加了期末考試的學生數)。每個數都不超過10000。

接下來有三塊輸入。第一塊包含 P 個線上程式設計成績 Gp;第二塊包含 M 個期中考試成績 Gmid−term;第三塊包含 N 個期末考試成績 Gfinal。每個成績占一行,格式為:

學生學号 分數

。其中

學生學号

為不超過20個字元的英文字母和數字;

分數

是非負整數(程式設計總分最高為900分,期中和期末的最高分為100分)。

輸出格式:

列印出獲得合格證書的學生名單。每個學生占一行,格式為:

學生學号

Gp Gmid−term Gfinal G

如果有的成績不存在(例如某人沒參加期中考試),則在相應的位置輸出“−1”。輸出順序為按照總評分數(四舍五入精确到整數)遞減。若有并列,則按學号遞增。題目保證學号沒有重複,且至少存在1個合格的學生。

輸入樣例:

6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
           

輸出樣例:

missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
           

注意點:

1.測試點4最開始沒過是因為沒有注意到未參與線上程式設計作業,但總評合格的情況。在最後輸出的時候加上

gp>=200

的限制條件就可以了。

知識點:

  1. map<string,int>

    map中的count方法可以用來判斷學号是否已經被記錄。
    使用count,傳回的是被查找元素的個數。如果有,傳回1;否則,傳回0。注意,map中不存在相同元素,是以傳回值隻能是1或0。
  2. struct的排序方法。

代碼

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
map<string,int> m_stu;
struct stru{
	string num;
	int gp; //gp=-1;
	int gmt;
	int gf;
	int g;
	
	stru(){ //初始化,可以不這麼麻煩,直接在前面初始化
		gp=-1;
		gmt=-1;
		gf=-1;
	}
} allg[30005];
bool comp(stru a, stru b){
	if(a.g!=b.g){
		return a.g>b.g;
	}
	else{
		return a.num<b.num;
	} 
}
int main(){
	int p,m,n;
	cin>>p>>m>>n;
	string stu;
	int in,w=0;
	for(int i=0; i<p; i++){
		cin>>stu>>in;
		if(in<200){	continue;}
		m_stu[stu]=w;
		allg[w].num=stu;
		allg[w].gp=in;
		w++;
	}
	for(int i=0; i<m; i++){
		cin>>stu>>in;
		if(!m_stu.count(stu)){
			m_stu[stu]=w;
			allg[w].num=stu;
			allg[w].gmt=in;
			w++;
		}
		else{
			int k=m_stu[stu];
			allg[k].gmt=in;
		}
	} 
	for(int i=0; i<n; i++){
		cin>>stu>>in;
		if(in<=33){ continue;}
		if(!m_stu.count(stu)){
			m_stu[stu]=w;
			allg[w].num=stu;
			allg[w].gf=in;
			w++;
		}
		else{
			int k=m_stu[stu];
			allg[k].gf=in;
		}		
	}
	for(int i=0; i<w; i++){
		if(allg[i].gmt>allg[i].gf){
			allg[i].g=allg[i].gmt*0.4+allg[i].gf*0.6+0.5;
		}
		else{
			allg[i].g=allg[i].gf;
		}
	}
	sort(allg, allg+w,comp);
	for(int i=0; i<w; i++){
		if(allg[i].g>=60 && allg[i].gp>=200){
			cout<<allg[i].num<<' '<<allg[i].gp<<' '<<allg[i].gmt<<' '<<allg[i].gf<<' '<<allg[i].g<<endl;
		}
	}	
}