欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1894A.Secret Sport
Secret Sport
Let's consider a game in which two players, A and B, participate. This game is characterized by two positive integers, and .
The game consists of sets, and each set consists of plays. In each play, exactly one of the players, either A or B, wins. A set ends exactly when one of the players reaches wins in the plays of that set. This player is declared the winner of the set. The players play sets until one of them reaches wins in the sets. After that, the game ends, and this player is declared the winner of the entire game.
You have just watched a game but didn't notice who was declared the winner. You remember that during the game, plays were played, and you know which player won each play. However, you do not know the values of and . Based on the available information, determine who won the entire game — A or B. If there is not enough information to determine the winner, you should also report it.
Input
Each test contains multiple test cases. The first line contains a single integer - the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer - the number of plays played during the game.
The second line of each test case contains a string of length , consisting of characters A and B. If , it means that player A won the -th play. If , it means that player B won the -th play.
It is guaranteed that the given sequence of plays corresponds to at least one valid game scenario, for some values of and .
Output
For each test case, output:
A— if player A is guaranteed to be the winner of the game.B— if player B is guaranteed to be the winner of the game.?— if it is impossible to determine the winner of the game.
Note
In the first test case, the game could have been played with parameters , . The game consisted of set, in which player A won, as they won the first plays. In this scenario, player A is the winner. The game could also have been played with parameters , . It can be shown that there are no such and values for which player B would be the winner.
In the second test case, player B won all the plays. It can be easily shown that in this case, player B is guaranteed to be the winner of the game.
In the fourth test case, the game could have been played with parameters , :
- In the first set, plays were played:
AAA. Player A is declared the winner of the set. - In the second set, plays were played:
AAA. Player A is declared the winner of the set. - In the third set, plays were played:
AABBB. Player B is declared the winner of the set. - In the fourth set, plays were played:
AABBB. Player B is declared the winner of the set. - In the fifth set, plays were played:
BBAB. Player B is declared the winner of the set.
In total, player B was the first player to win sets. They are declared the winner of the game.
Samples
7
5
ABBAA
3
BBB
7
BBAAABA
20
AAAAAAAABBBAABBBBBAB
1
A
13
AAAABABBABBAB
7
BBBAAAA
A
B
A
B
A
B
A
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |