编程介的小学生 2017-03-23 03:50 采纳率: 20.5%
浏览 748
已采纳

Tennis Scorer

Tennis is a very popular sport nowadays. In this problem, you are given a very simple task: recording the scores in tennis matches with the progress of matches given to you.
Here's a simple edtion of tennis rules that may help you (or do you want me to give you a ten-page's PDF?):

At first, we assume that all players here are experienced tennis players who won't make stupid mistakes so we can ignore some rules such as foot fault and touching the ball with one's body or clothes.

At the beginning of every point, the server will service the ball to the diagonal service court. If he failed (the ball doesn't fall into the service court), it is a "Fault". After a single fault, the server has one more chance to service. With a double fault, the server will lose this point. An additional rule is that if the ball fall into the service court after touching the net, it is called a "Let" and the server should serve again. If the serve is success, this point continues until:

The ball doesn't cross the net, we call it "Net"
The ball doesn't fall into the opponent's court, we call it "Out"
The opponent fails to return the ball before it hits the ground twice, we call it "Ace"

If it is a Net or Out, the player who hit the ball last loses the point, and if it is an Ace, he wins the point. (Maybe ace is known to you as service ace, but actually ace is "A shot that the opponent cannot hit", there are service aces, return aces and smash aces. Service ace is a service that the opponent cannot return, and return ace is the ace with the return of the service.)
If a player win his first point, the score is called 15 for that player, 30 and 40 are called for the second and the third point respectively. If one player win four points with his opponent's point no more than 2, he wins this game. However, if both players have won three points, the score is called deuce, and the next point won by a player is scored advantage for that player. If the same player win again, he wins the game; if the other does, it is remain deuce, until a player wins the two points immediately after deuce.

The formal match is 3 sets and 6 games, and the practice matches are usually 1 set 6 games, while some prefer simple matches with only 2 games. In this problem we just consider any match with S sets and G games (1 <= S <= 3, 1 <= G <= 6). That means, the one who wins G games first win the set, and the one who wins S sets win the match. But when the two players both win G - 1 (when G > 1) games, one has to win two games continuously to win the set. When the games are both G, it is the tiebreaker (discuss later).

When the total number of games are even, the first server (determined by toss before the match) serves in the next game, with game number odd, the other player serves.

In the tiebreaker, the points are scored with continuous integers and the first player wins 7 points will win the game (and the set). But if the points are both N (N>=6, no deuce), one has to win two continuous points to win the game. The player who will serve this game serves the first point, and when the total points are odd the server is changed.

If a player is about to win a game (with one more point), it is called game point or break point according to whether he is the server or not. And the same is with set point and match point.

In doubles (every team has two players, and the court is wider), the rules are almost the same (you can just change the word player to team), with one additional - the order for server and receiver. The two players in the same team change roles every game that it is their team's turn to serve. For example, with P1 and P2's team against P3 and P4's team, if the first game P1 is the server and the second game P3 is, P2 and P4 will serve the next two games and then it is turn to P1. For receiver (only one player is allowed to receive the service), in the same game the two player change roles every point, and change the first receiver every game it is their opponents' turn to serve. For the former example, if when P1 serves P3 receive the first point, then P4 will receive the next point, then P3; and when P2 serves P4 will receive the first point. It is the same in the tiebreaker (you can simply consider two points as a "game").

Input

For each test case, the first line is "P1 vs. P2" or "P1 & P2 vs. P3 & P4" in doubles, where P1, P2, P3, P4 are names of players with no more than 20 non-space characters each and differ with any words in tennis glossary. P1 or P1's team always service first, and in doubles P1 and P3 always serve and receive first in their teams.

The second line is "S Set(s) G Game(s)" that specifies the game and set numbers. (1 <= S <= 3, 1 <= G <= 6)

The progress of the match start from the third line.

Each line contains one of the contents below:

Fault
Let
Service Ace
Return Ace
Pi Ace
Pi Out
Pi Net

where Pi is a player's name.
The case ends when the match finishes.

There's a blank line between every two cases, processing to the end of file.

Output

For each test case, you program will output the score each time the score is changed.

During a game, just output "Ps - Pr" in a single line, where Ps is the point of the server and Pr of the receiver.

When encountering deuce, the first time just output "Deuce", otherwise output "Deuce #N" where N is the times of deuces in current game. Output "Adv. - 40" or "40 - Adv." an point after deuce according to which side is advance.

If it is the end of a game, do not output the points (no one would like to see 0 - 0), output the numbers of games the two players/teams win instead, start with the first server (P1 or P1's team).

If it is also the end of a set, output the numbers of sets instead, start with the first server, too.

If it is a game/break/set/match point, output it in an extra line with the initial letter of each word uppercase. (Only one line with priority match > set > break = game)

At the end of the match, output an extra line "Pi Wins" or "Pi & Pj Win".

Output a blank line between every two cases.

Sample Input

Max vs. Tina
1 Set 2 Games
Service Ace
Service Ace
Return Ace
Service Ace
Service Ace
Tina Ace
Max Ace
Tina Out
Max Ace
Tina Net
Sample Output

15 - 0
30 - 0
30 - 15
40 - 15
Game Point
1 - 0
15 - 0
15 - 15
15 - 30
15 - 40
Match Point
1 - 0
Max Wins

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-30 15:42
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度