+ محدودیت زمان: ۱ ثانیه
+ محدودیت حافظه: ۲۵۶ مگابایت
----------
*Who do you like more, Colonel or Morteza? She asks.*
*Colonel. everybody, but Erfan, replies. (yes, even Morteza)*
Erfan is still faithful to Morteza so he decides to be absolutely sure about this matter of life or death. He knows that there’s an upcoming tennis match between Colonel and Morteza. He will therefore choose between them based on the result of the match.
Due to the importance of the match, Colonel and Morteza are playing behind closed doors and Erfan is only be able to hear them from behind the walls. The sequence of the sounds that Erfan hears consist of the
following:
+ `G`: Ball hits the ground
+ `R`: Ball hits a racket
+ `N`: Ball hits the net
+ `?`: Unknown. can be `G`, `R`, or `N`
Erfan has written down the sequence of the sounds that he has heard. He wants to know who wins more games among all possible valid game sequences.
He has seen them play before so he also knows how the game is played. He knows that a valid sequence consists of multiple consecutive valid scores and the player with the most scores wins a sequence. (Morteza wins the sequence in case of a tie in scores)
In a valid score:
+ Always Colonel starts by serving (hits the ball).
+ ball hitting the net once, or the ground twice in a row ends the score. In the latter case the last player who has just hit the ball scores. It’s the other way around in the former case. This can happen after the serves and after regular hits. (That means in case of `N`, the ball hits the net and simply falls back in the hitter’s side, causing him to lose a point)
+ a player can hit the ball if it has not yet hit the ground, or if it has hit the ground once. In case of answering a serve, the player can’t hit the ball in the air (this will be an invalid sequence) and will have to let the ball hit the ground once.
+ The ball will never hit the net right after it has hit the ground.
Oh and In case of a tie in the number of possible game sequences won, Dog ate… Let’s say Morteza wins again. It is guaranteed that at least one valid sequence exists.
# ورودی
The first line of input contains $T$, the number of test cases.
$$1 \leq T \leq 50$$
Each of the following $T$ lines contains a single string consisting of `G`, `R`, `N`, and `?`.
$$length of each test case \leq 11$$
# خروجی
For each test case If Morteza is the winner, output `Morteza to doost dashtani hasti`. Otherwise output `Nasirifar to doost dashtani hasti`.
# مثالها
## ورودی نمونه ۱
```
2
??RG???
???
```
## خروجی نمونه ۱
```
Morteza to doost dashtani hasti
Nasirifar to doost dashtani hasti
```
Here are all the valid sequences for the first test case (scores are separated by space for clarity):
+ `RGRGRGG`
+ Colonel $1$ : $0$ Morteza
+ `RNRGRGG`
+ Colonel $0$ : $2$ Morteza
+ `RGRGRRN`
+ Colonel $1$ : $0$ Morteza
+ `RN RGRRN`
+ Colonel $0$ : $2$ Morteza
+ `RGRGG RN`
+ Colonel $0$ : $2$ Morteza
+ `RN RGG RN`
+ Colonel $1$ : $2$ Morteza
Morteza Wins in $4$ of the possible valid sequences, Colonel wins in $2$.
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.