题目描述
Lightning McQueen, Strip Weathers, and Chick Hicks are cars that compete in different races against each other. Some races — such as the Piston Cup — are considered more prestigious than others, while others — such as Thunder Hollow — are somewhat less prestigious (we realize only Lightning raced there). Given a list of races of various prestige, and who won each race, help Lightning and his competitors determine who is the best racer.
You will be provided with a list of c cars who are racing in these races. You will also be given a list of r races, each with a name, a prestige, and the first three cars to cross the finish line. Unlike the movie, there are no ties.
The value, v, of a race for the winner is equal to the total prestige of the race. The second place finisher has one-half that value (rounded down), and the third place winner has one-fourth — not one-third! — of the total prestige value (also rounded down). Note that some cars may not finish within the first three placements; these cars receive a value of 0 for such races. Racers accumulate value from each race throughout the entire season.
输入
The first line of the file, n ≤ 500, will be the number of test cases.
The first line of each test case is a string, naming the racing season. The next line contains a single number 3 ≤ c ≤ 100, which is the number of cars that are racing. The next c lines contain the name of each competitor as a string. The next line is a number 2 ≤ r ≤ 100, which is the number of races to consider.
The next r lines will have the information for one race on a single line (space separated), consisting of five values: the name (a string), a prestige value (non-negative integer), and the three winners (first place,second place, and third place, in that order).
All provided strings (racing seasons, car names, and race names) will be strings consisting of letters of either case, numbers, and/or underscores. All integers, as well as all computed values, will fit in a 32-bit signed integer variable.
All finishers in the various races will be listed in the list of c cars, but some cars may never finish in the first three places of a race. Not surprisingly, any given racer can only be listed once for a given race (i.e., one can’t place first and second place).
输出
For each test case, output the racing season name, followed by a colon. The next c lines should contain
the names of each racer followed by their total score. The list of racers should be in lexicographical order (“lexicographical” ordering is like alphabetical ordering, but allowing numbers as well). Keep in mind that,in lexicographical order, “car 3” comes after “car 20”. There should be no blank lines between output cases.
样例输入
1 2005_Season 4 Lightning_McQueen Strip_Weathers Chick_Hicks Slowy_McSlowFace 3 Glen_Ellyn 200 Lightning_McQueen Strip_Weathers Chick_Hicks Dinoco_400 240 Lightning_McQueen Strip_Weathers Chick_Hicks Piston_Cup 300 Chick_Hicks Strip_Weathers Lightning_McQueen
样例输出
2005_Season: Chick_Hicks 410 Lightning_McQueen 515 Slowy_McSlowFace 0 Strip_Weathers 370
题目涵义:c个选手参加比赛,前三名分别可以得到这场比赛威望值的全部,二分之一,四分之一的威望。得出r场比赛后各位选手分别得到的威望,按照选手名字的字母排序输出。
思路:将各位选手的分数全部初始化为0,存在map中,每场比赛前三名加上威望值,按照名字排序输出。注意每个样例需要初始化。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct cmp{
bool operator()(const string& k1,const string& k2)const{
return k1<k2;
}
};//对map排序
map<string,int,cmp> m;
char race[100010];
string n;
int main()
{
int t,a,b,r;
scanf("%d",&t);
while(t--){
getchar();
scanf("%s",race);
printf("%s:\n",race);//注意输出包含(:)
m.clear();//每一组样例都需要清空再加新数据
scanf("%d",&a);
for(int i=0;i<a;i++){
getchar();
cin>>n;
m[n]=0;
}
scanf("%d",&b);
for(int i=0;i<b;i++){
getchar();
cin>>n>>r;
for(int j=0;j<3;j++){
cin>>n;
if(j==0){
m[n]+=r;
}
else if(j==1){
m[n]+=(r/2);
}
else{
m[n]+=(r/4);
}
}
}
map<string,int>::iterator iter;
for(iter=m.begin();iter!=m.end();++iter)
cout<<(*iter).first<<' '<<(*iter).second<<endl;
}
return 0;
}