A. Angry Students

  网址: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.22801763489

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.722801787297

 

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 (1t1001≤t≤100 ). The following 2t2t lines contain descriptions of groups of students.a==1

The description of the group starts with an integer kiki (1ki1001≤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=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e7+10;
char a[maxn];
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        scanf("%s",a);
        int ans=0;
        int k=0;
        for(int i=0;i<n;i++){
            if(a[i]=='A'){
                while(a[i+1]=='P'){
                    k++;
                    i++;    
                }    
            }
            ans=max(k,ans);
            k=0;
        }
        printf("%d\n",ans);
    }
    return 0;
} 
View Code
复制代码
posted @   lipu123  阅读(435)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示