Volleyball Scores
Time limit2sMemory limit512 MB
Track a sequence of volleyball touches and report the score, or flag a wrong serve.
- Level
Medium6 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Volleyball has been an Olympic sport since 1964. Two teams of 6 players each (2 players each in beach volleyball) hit a ball back and forth, and a team may touch the ball at most three times before it has to send the ball to the other side. More rules apply, such as the ban on the same player touching the ball twice in a row, so keeping the score is tedious work. Write a program that keeps it.
These are the rules this problem uses. Each team has 6 players. Players 1 to 6 belong to Team A, and players 7 to 12 belong to Team B. The two teams take turns serving, so the team that serves a rally is the team that did not serve the previous rally. Either team may serve the first rally.
The other team wins the point when one of the following happens to your team.
- One of your players touches the ball twice in a row.
- Players of your team touch the ball at least four times in a row.
- The ball touches the ground in your court.
- The ball touches the ground out of bounds, and one of your players was the last to touch it.
- One of your players touches the ball right after one of your players served it.
A point ends the rally, and the next touch in the sequence is the serve of the next rally.
Given the sequence of touches, find the current score. Serving counts as touching the ball. When a player of the wrong team served at any point, report that instead of the score.
Effects of the net are ignored here, together with a few other details, including the rule that the serving player normally rotates.
Input
The first line contains an integer (), the number of data sets in the file. data sets follow, each of this form.
The first line of a data set contains an integer (). The second line contains ball touches separated by one space each.
- An integer () means that player touched the ball. This touch may be a serve.
- The letter A or the letter B means that the ball touched the ground in the court of Team A or in the court of Team B.
- The letter X means that the ball touched the ground out of bounds.
The first ball touch of a data set is always an integer, the player who served first. The rally may still be in progress when the sequence ends. Apart from wrong serves, the input never contains an impossible sequence.
Output
For each data set, print "Data Set x:" on a line of its own, where x is the number of the data set counted from 1. On the next line print the score of Team A and the score of Team B, separated by one space. When a player of the wrong team served at any point of the sequence, print "Wrong Serve" on that line instead of the score. Print one blank line between two consecutive data sets.