跳到正文

题解

题解 CF1287A 【Angry Students】

gyh20约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年6月14日
更新
2026年6月14日
篇幅
约 1 分钟
获赞
1
题目
CF1287A

版本

  1. v1当前

统计每一个人变生气的时间(如果可以变生气),求一个最大值即可。

代码如下:

C++
#include<bits/stdc++.h>
using namespace std;
#define re register
inline int read(){
	re int t=0,f=1;
	re char v=getchar();
	while(v<'0'||v>'9'){
		if(v=='-')f=-1;
	v=getchar();}
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t*f;
}
int n,k;
char s[100002];
int main(){
n=read();
while(n--){
	k=read();
	int ans=0;
	scanf("%s",s+1);
	for(re int i=1;i<=k;++i){
		if(s[i]=='A'){
			int tmp=i+1,pp=0;
			while(tmp<=k&&s[tmp]=='P')++tmp,++pp;
			ans=max(ans,pp);
		}
	}
	printf("%d\n",ans);
}
}
原文