欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1898A.Milica and String
Milica and String
Milica has a string of length , consisting only of characters A and B. She wants to modify so it contains exactly instances of B. In one operation, she can do the following:
- Select an integer () and a character ( is equal to either
AorB). - Then, replace each of the first characters of string (that is, characters ) with .
Milica does not want to perform too many operations in order not to waste too much time on them.
She asks you to find the minimum number of operations required to modify so it contains exactly instances of B. She also wants you to find these operations (that is, integer and character selected in each operation).
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of test cases follows.
The first line of each test case contains two integers and (, ) — the length of the string and the number of characters B Milica wants to appear in in the end.
The second line of each test case contains the string of length , consisting only of characters A and B.
Output
For each test case, in the first line output a single integer — the minimum number of operations Milica should perform.
In the -th of the next lines output an integer () and a character ( is 'A' or 'B') — the parameters of the -th operation as described in the statement.
If there are multiple solutions with the minimum possible number of operations, output any of them.
Note
In the first test case, there are already characters B in , so Milica does not have to perform any operations.
In the second test case, the only way to achieve characters B in in one operation is to replace the first character of by B on the first operation: AABAB BABAB.
In the third test case, the only way to achieve characters B in in one operation is to replace the first characters of by A on the first operation: BBBBB AAAAA.
In the fourth test case, one of the ways to achieve characters B in in one operation is to replace the first characters of by A on the first operation: BAA AAA. Note that "1 A" and "3 A" are also correct one-operation solutions.
Samples
5
5 2
AAABB
5 3
AABAB
5 0
BBBBB
3 0
BAA
10 3
BBBABBBBAB
0
1
1 B
1
5 A
1
2 A
1
6 A
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |