1. 程式人生 > >團體程式設計天梯賽 L2-027 名人堂與代金券 (25 分)C++ STL

團體程式設計天梯賽 L2-027 名人堂與代金券 (25 分)C++ STL

對於在中國大學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<bits/stdc++.h>
using namespace std;
typedef pair<string,int> PAIR;
bool cmp(const PAIR &x,const PAIR &y){//根據題意寫的排序規則
  if(x.second>y.second) return true;//分數高排在前面
  else if(x.second==y.second) return x.first<y.first;//分數相等按名字升序排
  else return false;
}
int main(){
  map<string,int> op;
  char c[20];
  int o;
  int n,m,k;
  cin>>n>>m>>k;
  int sum=0;//代金券金額
  for(int i=0;i!=n;++i){
    scanf("%s",c);
    scanf("%d",&o);
    op[c]=o;
    if(o>=m) sum+=50;
    else if(o>=60&&o<m) sum+=20;
  }
  vector<PAIR> oo(op.begin(),op.end());
  sort(oo.begin(),oo.end(),cmp);
  printf("%d\n",sum);
  int cnt=1;//名次,初始為1,代表第一名
  cout<<cnt<<" "<<oo[0].first<<" "<<oo[0].second<<endl;
  for(auto i=1;i!=oo.size();++i){
    if(oo[i].second!=oo[i-1].second){
    	cnt=i+1;//分數不相等名次變大
	}
	if(cnt>k) break;
	cout<<cnt<<" "<<oo[i].first<<" "<<oo[i].second<<endl;
  }
}