网址: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. UNION JOIN 连接表

    使用UNION JOIN进行多表连接,与9.3节介绍的各种表的连接类型不同,它并不对表中的数据进行任何匹配处理,而只是把来自一个源表中的行与另一个源表中的行联合起来,生成的结果表中包括第一个表中的所有 ...

  2. [Linux] Ubuntu18.04 安装之后配置过程

    前言  最终还是安装了Ubuntu 虽然一开始想用Deepin 但是死活安装不上,我也很绝望(引导一直找不到 恢复BIOS默认设置也还是不行 所以 有些绝望啊....)  所以 为了让以后的我不再那么 ...

  3. Apache Kafka(十)Partitions与Replication Factor 调整准则

    Partitions与Replication Factor调整准则 Partition 数目与Replication Factor是在创建一个topic时非常重要的两个参数,这两个参数的取值会直接影响 ...

  4. 使用 navigator.sendBeacon() 上报数据

    http://kaifage.com/notes/76/navigator-sendBeacon.html 如某些统计系统,在页面unload时,如果要上报当前数据,采用xhr的同步上报方式,会阻塞当 ...

  5. winform学习(1)初识winform

    winform是Windows窗体应用程序 在窗体设计界面  单击鼠标右键--查看代码,即可转到Form1.cs的代码界面 从代码界面转到窗体设计界面的三种快捷方法:①双击解决方案资源管理器的 For ...

  6. MySQL导入含有中文字段(内容)CSV文件乱码解决方法

    特别的注意:一般的CSV文件并不是UTF-8编码,而是10008(MAC-Simplified Chinese GB 2312),所以再通过Navicat导入数据的时候需要指定的编码格式是10008( ...

  7. APL: ANSYS Power Library

    1. creating accurate switching current waveforms (profiles) 2.output-state dependent decoupling capa ...

  8. MyBatis(5)——解决属性名与列名不一致的问题

    解决属性名与列名不一致的问题 问题描述: 当实体类的属性与数据库的列名不对应时取不到该列数据 说明:MyBatis会根据查询的列名设值(列名的setter方法),然后以此列名为做查询等操作,在此过程中 ...

  9. go使用错误概览

    1. 解决:GO语言中要提供给外面访问的方法或是结构体必须是首字母大写.这个结构体只有结构体名大写了,而里面的字段没有首字母大写,而GO语言在模板调用时应该认为是两个不同的过程,所以找不到值.于是把结 ...

  10. AcWing 846. 树的重心

    #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> ...