Connection Status:
Competition Arena > IHWCPenalty
SRM 846 · 2023-05-22 · by misof · Simulation
Class Name: IHWCPenalty
Return Type: String
Method Name: resolve
Arg Types: (string)
Problem Statement

Problem Statement

This problem is inspired by the currently running Ice Hockey World Championships.


In this problem we will simulate a penalty box during a hockey game.

The current hockey game is played between the Lowercase Lions and the Uppercase Urchins. We will use some letters to denote game actions as follows:

  • 'p': a player of Lowercase Lions was sent to the penalty box
  • 's': a player of Lowercase Lions has finished serving their penalty and has returned from the penalty box
  • 'g': the Lowercase Lions scored a goal
  • 'P', 'S', 'G': the same for the Uppercase Urchins

If team X has fewer players in the penalty box than team Y, we say that team X is playing a power play and that team Y is playing short-handed. If a team scores a goal during their power play, one player of the opposing team returns from the penalty box. In all other cases the goal has no effect on the penalty box.


You are given the String events that uses the letters mentioned above to describe a sequence of actions during a game, in chronological order.

The answer you should return is a String containing one character for each goal, in chronological order. For each goal, the character should be 'P' if the goal was scored during the scoring team's power play, 'S' if it was scored short-handed, and '=' (equals) if it was scored in a situation when both teams had the same number of players in the penalty box.

Constraints

  • events will contain between 0 and 1000 characters, inclusive.
  • Each character in events will be one of "psgPSG".
  • The characters 's' and 'S' will never be used in a situation in which the penalty box contains no players from the respective team.
Examples
0)
"gggGgGg"
Returns: "======="

Lowercase Lions won this game 5:2. There were no penalties, so all goals were scored at equal strength.

1)
"PPggg"
Returns: "PP="

Two players of the Urchins were sent to the penalty box. Then, the Lions scored a power-play goal (which returned one of the punished Urchins' players), another power-play goal, and finally a goal at equal strength.

2)
"PPpPGGg"
Returns: "SSP"

Three Urchins and one Lion were sent to the penalty box. Then the Urchins scored two short-handed goals, and finally the Lions scored a power-play goal. At the end of the game there were still two Urchins and one Lion in the penalty box.

3)
"gGpPgGgGsSgG"
Returns: "========"

All goals in this game were scored at equal strength -- some of them in the situation when each team had one player in the penalty box.

4)
"GgpPPGgg"
Returns: "==SP="

Short-handed goals have no effect on the penalty box. Hence, after the third goal of this game the penalty box still contains one Lion and two Urchins. The fourth goal is a power-play goal for the Lions. After that goal one Urchin returns from the penalty box, so now each team has one player serving a penalty and the fifth goal is scored at equal strength.

5)
"ggPPgSg"
Returns: "==P="

One of the two Urchins' penalties is ended by the third goal of the game, the other penalty then expires. By the time the fourth goal is scored the penalty box is empty again.

Submissions are judged against all 86 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class IHWCPenalty with a public method string resolve(string events) · 86 test cases · 2 s / 256 MB per case

Submitting as anonymous