欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2204A.Passing the Ball
Passing the Ball
During a physical education class, students are lined up, numbered from to from left to right.
For each student, it is known that if they receive the ball, they will pass it either to the neighbor on their left or to the neighbor on their right. This is specified by a string of characters. Each character of the string is either L or R, where is L if the -th student passes the ball to student , or is R if the -th student passes the ball to student . The first student always passes the ball to the second, and the last one to the second last (in other words, the string starts with the character R and ends with the character L).
Consider the following process:
- first, the first student receives the ball;
- then, exactly times, the following occurs: the student who currently has the ball passes it to their neighbor (according to the rules described above).
Your task is to determine how many students will receive the ball at least once during this process.
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains a single integer () — the number of students;
- the second line contains — a sequence of characters
LandR. The first character of the sequence isR, and the last isL.
Output
For each test case, print one integer — the number of students who will receive the ball at least once during the described process.
Note
In the first example, student receives the ball and passes it to student , who returns it back to student , who passes it back to student , and so on. Only students and received the ball.
In the second example, student passes the ball to student , who passes it to student , who passes it to student , who passes it to student , who passes it to student , who returns it to student . Each student received the ball at least once.
Samples
3
4
RLRL
6
RRRRRL
9
RRLRRRRRL
2
6
3
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |