#K35537. Player Action Score Calculator
Player Action Score Calculator
Player Action Score Calculator
You are given a mapping of actions to their corresponding point values and a list of players with the actions they performed. Your task is to calculate the total score for each player by summing the point values of all actions they performed. If an action is not found in the mapping, it contributes 0 points.
The input is provided from standard input (stdin
) in the following format:
- The first line contains an integer p, the number of distinct actions.
- The next p lines each contain an action (a string without spaces) followed by an integer representing its point value.
- The following line contains an integer m, the number of players.
- For each player, there are three sets of inputs:
- A line with the player's name (a single string).
- A line with an integer k representing the number of actions performed by the player.
- If k > 0, a line with k space-separated action names. If k is 0, this line may be empty.
Your program should output the total score for each player on separate lines in the format:
player_name total_score
If there are no players, the program should produce no output.
For example, if the points mapping is given as {\(\texttt{jump:10}\), \(\texttt{run:5}\), \(\texttt{shoot:20}\)} and the actions for players are provided as below, then:
Input: 3 jump 10 run 5 shoot 20 2 Alice 4 jump run shoot jump Bob 2 run run Output: Alice 45 Bob 10
inputFormat
The input is read from standard input (stdin
) and has the following structure:
- An integer p representing the number of actions in the points mapping.
- p lines follow, each containing an action (a string without spaces) and an integer (the point value) separated by a space.
- An integer m representing the number of players.
- For each of the m players:
- A line containing the player's name.
- A line containing an integer k denoting the number of actions taken by the player.
- If k > 0, a line with k space-separated action names; otherwise, the line can be empty.
outputFormat
For each player, print a line containing the player's name and their calculated total score, separated by a space. The order of players in the output should be the same as the order in the input.
If there are no players, the program should output nothing.
## sample3
jump 10
run 5
shoot 20
2
Alice
4
jump run shoot jump
Bob
2
run run
Alice 45
Bob 10
</p>