网址:http://codeforces.com/problemset/problem/1287/A

It's a walking tour day in SIS.Winter, so tt 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 ii in the string describing a group then they will throw a snowball at the student that corresponds to the character with index i+1i+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.

Input

The first line contains a single integer tt  — the number of groups of students (1≤t≤1001≤t≤100 ). The following 2t2t lines contain descriptions of groups of students.

The description of the group starts with an integer kiki (1≤ki≤1001≤ki≤100 ) — the number of students in the group, followed by a string sisi , consisting of kiki letters "A" and "P", which describes the ii -th group of students.

Output

For every group output single integer — the last moment a student becomes angry.

Examples
Input

Copy
1
4
PPAP
Output

Copy
1
Input

Copy
3
12
APPAPPPAPPPP
3
AAP
3
PPA
Output

Copy
4
1
0
Note

In the first test, after 11 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 11 minute — AAPAAPPAAPPP
  • after 22 minutes — AAAAAAPAAAPP
  • after 33 minutes — AAAAAAAAAAAP
  • after 44 minutes all 1212 students are angry

In the second group after 11 minute, all students are angry.

解题思路:

就是在字符串中找A并且向后枚举,找他能向后传染的最大值

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e7+;
char a[maxn];
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
scanf("%s",a);
int ans=;
int k=;
for(int i=;i<n;i++){
if(a[i]=='A'){
while(a[i+]=='P'){
k++;
i++;
}
}
ans=max(k,ans);
k=;
}
printf("%d\n",ans);
}
return ;
}

A. Angry Students的更多相关文章

  1. codeforces 1287A -Angry Students(模拟)

    It's a walking tour day in SIS.Winter, so t groups of students are visiting Torzhok. Streets of Torz ...

  2. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  3. Codeforces Round #612 (Div. 2)

    https://codeforces.com/contest/1287/ A - Angry Students 题意:求A后面的P最长连续有几个? 题解:? int n; char s[200005] ...

  4. Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you are Angry.Think Twice.Act Wise.

    Don't make a promise when you are in Joy. Don't reply when you are Sad.Don't take decisions when you ...

  5. Advice for students of machine learning--转

    原文地址:http://www.mimno.org/articles/ml-learn/ written by david mimno One of my students recently aske ...

  6. HDOJ 2444 The Accomodation of Students

    染色判读二分图+Hungary匹配 The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limi ...

  7. Spring-2-B Save the Students(SPOJ AMR11B)解题报告及测试数据

    Save the Students Time Limit:134MS     Memory Limit:0KB     64bit IO Format:%lld & %llu   Descri ...

  8. HD2444The Accomodation of Students(并查集判断二分图+匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. codeforces A. Group of Students 解题报告

    题目链接:http://codeforces.com/problemset/problem/357/A 题目意思:将一堆人分成两组:beginners 和 intermediate coders .每 ...

随机推荐

  1. TD - 单选框 - RadioButton

    基本方法 Html - 默认选中 //checked="true" - 默认选中 <input dojoType="bootstrap.form.RadioButt ...

  2. 【转载】extern "C" __declspec(dllexport) __declspec(dllimport) 和 def

    转自:http://www.cppblog.com/FateNo13/archive/2009/08/03/92052.html 前面的extern "C"  __declspec ...

  3. 如何强制文件上传git仓库里

    1.首先在本地创建一个文件夹里写入一个txt文件 2.然后复制你仓库的地址 3.平时正常操作都是这样上传不上 4.没关系我们使用强制上传 代码是 git push -f “你的仓库地址”   mast ...

  4. SpringMVC框架应用

    SSMSpringMVC框架 1.    MVC设计模式:模型.视图.控制器: 视图:负责格式化数据并把他们呈现给用户,包括数据展示.用户交互.数据验证.界面设计等功能.对应组件:JSP或者HTML ...

  5. 2019-08-05 纪中NOIP模拟B组

    T1 [JZOJ1432] 输油管道 题目描述 请你帮忙设计一个从城市M到城市Z的输油管道,现在已经把整个区域划分为R行C列,每个单元格可能是空的也可能是以下7种基本管道之一: 油从城市M流向Z,‘+ ...

  6. Books Exchange (hard version)

    The only difference between easy and hard versions is constraints. There are nn kids, each of them i ...

  7. 2019牛客多校第四场J free 最短路

    free 题意 给出一个带权联通无向图,你需要从s走到t,你可以选择k条变让他们的权值为0问从s到t的最小权值是多少? 分析 思考一下,如果不带k条白嫖这个条件,那么这就是一个简单的dji就搞定了,我 ...

  8. 配置SSH使用密钥认证:实现免输入密码登陆

    一.实际工作生产场景分析 张三是某公司员工,由于业务上的需求,需要经常使用SSH工具登陆服务器A的root账户进行操作,为避免重复进行密码验证身份.现采用张山的公钥发送给服务器A,免输入密码登陆到服务 ...

  9. 联网调试DE1

    步骤:打开PUTTY,com3,串口,115200 重启开发板, 输入root, 输入   cd /mnt 输入    ifconfig 尝试一下自动分配网址:udhcpc 网络直连失败,原因占时不知 ...

  10. Java - 集合 - List

    1.List实现类:ArrayList.LinkedList.Vector ArrayList使用: void test() { //声明 List<String> testlist = ...