A13254 | Angry Students
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It's a walking tour day in SIS.Winter, so $t$ groups of students are visiting Torzhok. Streets of Torzhok are so narrow that students have to go in a row one after another.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
- "A" corresponds to an angry student
- "P" corresponds to a patient student
Such string describes the row from the last to the first student.
Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index $i$ in the string describing a group then they will throw a snowball at the student that corresponds to the character with index $i+1$ (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.
Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.
Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.
Initially, some students are angry. Let's describe a group of students by a string of capital letters "A" and "P":
- "A" corresponds to an angry student
- "P" corresponds to a patient student
Such string describes the row from the last to the first student.
Every minute every angry student throws a snowball at the next student. Formally, if an angry student corresponds to the character with index $i$ in the string describing a group then they will throw a snowball at the student that corresponds to the character with index $i+1$ (students are given from the last to the first student). If the target student was not angry yet, they become angry. Even if the first (the rightmost in the string) student is angry, they don't throw a snowball since there is no one in front of them.
Let's look at the first example test. The row initially looks like this: PPAP. Then, after a minute the only single angry student will throw a snowball at the student in front of them, and they also become angry: PPAA. After that, no more students will become angry.
Your task is to help SIS.Winter teachers to determine the last moment a student becomes angry for every group.
输入格式
The first line contains a single integer $t$ — the number of groups of students ( $1 \le t \le 100$ ). The following $2t$ lines contain descriptions of groups of students.
The description of the group starts with an integer $k_i$ ( $1 \le k_i \le 100$ ) — the number of students in the group, followed by a string $s_i$ , consisting of $k_i$ letters "A" and "P", which describes the $i$ -th group of students.
The description of the group starts with an integer $k_i$ ( $1 \le k_i \le 100$ ) — the number of students in the group, followed by a string $s_i$ , consisting of $k_i$ letters "A" and "P", which describes the $i$ -th group of students.
输出格式
For every group output single integer — the last moment a student becomes angry.
输入输出样例
输入 #1
1 4 PPAP
输出 #1
1
输入 #2
3 12 APPAPPPAPPPP 3 AAP 3 PPA
输出 #2
4 1 0
In the first test, after $1$ minute the state of students becomes PPAA. After that, no new angry students will appear.
In the second tets, state of students in the first group is:
- after $1$ minute — AAPAAPPAAPPP
- after $2$ minutes — AAAAAAPAAAPP
- after $3$ minutes — AAAAAAAAAAAP
- after $4$ minutes all $12$ students are angry
In the second group after $1$ minute, all students are angry.
In the second tets, state of students in the first group is:
- after $1$ minute — AAPAAPPAAPPP
- after $2$ minutes — AAAAAAPAAAPP
- after $3$ minutes — AAAAAAAAAAAP
- after $4$ minutes all $12$ students are angry
In the second group after $1$ minute, all students are angry.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted