问题 E: Racer Car Ranking

题目描述

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.

样例输入 Copy

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

样例输出 Copy

2005_Season:
Chick_Hicks 410
Lightning_McQueen 515
Slowy_McSlowFace 0
Strip_Weathers 370

卡的比较难受的一个题目,一直不知道错误在哪里,
最后才知道题目需要四舍五入,当时把分数存成了double类型,就没有四舍五入(编程不需要视力...)
AC代码
```

#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

string sea;
string s[110];
map <string, double> rac;
int main()
{
int T;
cin >> T;
while(T -- )
{
cin >> sea;
sea += ':';
int c;cin >> c;//4
for(int i = 0; i < c; i ++ )
{
string t;
cin >> t;
rac[t] = 0;
s[i] = t;
}
int r;cin >> r;//3
for(int j = 0; j < r; j ++ )
{
string t;cin >> t;
int temp;cin >> temp;//200
for(int i = 0; i < 3; i ++ )
{
string t;
cin >> t;
if(i == 0)rac[t] += temp;
else if(i == 1)rac[t] = rac[t] + temp / 2;
else rac[t] = rac[t] + temp / 4;
}
}
cout << sea << endl;
sort(s, s + c);
for(int i = 0; i < c; i ++ )
{
cout << s[i] << ' ' << rac[s[i]] << endl;
}
}
return 0;
}


```
posted @ 2021-04-15 20:31  梨花满地  阅读(104)  评论(0)    收藏  举报