## RAFANOLE - Nadal vs Djokovic

no tags

Rafael Nadal vs Novak Djokovic is probably the fiercest rivalry in tennis right now. Now your task is very simple.
You are given a string containing the scores of a single set(A set consists of many games) between these two stalwarts.
N denotes Nadal and D denoted Djokovic.
For those who are new to tennis , have a look of the rules online.
Anyway small desciption about the rules:

Now how a player wins a single game?

In a game scores are incremented as follows:
15,30,40
A player wins if scores are like 40-0,40-15,40-30.
If tied at 40-40., it is called Deuce.
If N wins next he has an Advantage and if he loses the next volley he comes back to Deuce.
After Advantage if the player wins the immediate volley he wins that game.

Simply put the player who wins 6 games first (provided he has won two games more than his opponent) wins the set.
For eg., 6-1,6-2,6-3,6-4 are all valid.

If 1 player has won 6 games and the other has won 5 games the match continues.(7-5 is also a valid scoreline)
If both the players are deadlocked at 6-6, then we have a tiebreaker.
In the tiebreaker the scores are counted normally (1,2,3,....)
The person who reaches 7 points first and is atleast 2 more than his opponent wins the set.
Eg: 7-0,7-1,7-2.....7-5 are valid.
If the scenario is 7-6 the match proceeds until one of the players scores two points more than the other.
Eg: Even 10-8 is valid.

Input:
1st line - No. of test cases

Next T lines consist of strings denoting who won a volley.

Output:

Winner  Score (tie breaker score if any)

Loser  Score

Example:

Input:
2
N N N N N N N N N N N N N N N N N N N N D D D D D D D D N N N N
D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D D D N N N N N D

Output:
N 6
D 2

D 7 (7-5)
N 6

hide comments
 < Previous 1 2 Next > Vipul Srivastava: 2017-01-16 15:06:10 No blank line after each test case in the output. Faiz Malik: 2014-09-02 00:39:13 My 100th AC in 1st go :) n.7n: 2014-02-27 11:39:22 Tricky case for those who get WA: Input: N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N N N N D D D D N D N D N D N D N D N N D N D N D N D N D N D D N D N D N D N D N D N D N D N D N N Output: N 7 (10-8) D 6 Gaara: 2014-02-06 15:32:46 AC on first attempt easy one..:) just follow the rule no rocket science and beware of taking input takeit using getline thanx to @Kimi Räikkönen Last edit: 2014-02-06 15:33:14 |RAMSDEN|: 2014-01-19 17:32:39 @author can u pls chk my soln id 10900959 getting wrong answer anurag garg: 2013-12-18 18:54:58 lots of condition...... n.7n: 2013-11-16 20:29:18 @ Deven : All input test cases shall be assumed to be valid. Last edit: 2013-11-13 15:34:13 albertg: 2013-11-16 20:29:18 My 100th AC :) Deven: 2013-11-16 20:29:18 Would the Input be till end of the Match only ?? Or will some extra things can also be given and the program should recognise it by itself that the match is over and it should stop.?? Saimadhav Heblikar: 2013-11-16 20:29:18 heads up,the there is no \n after each test case(as shown in the sample).cost me 4 nzec

 Added by: n.7n Date: 2013-10-21 Time limit: 1s Source limit: 50000B Memory limit: 1536MB Cluster: Cube (Intel G860) Languages: All except: ASM64 Resource: Own