跳到正文

题解

CF1287A 题解

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

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
2
题目
CF1287A

版本

  1. v1当前

思路:每个人都把自己被传染的时间标出来,挨个遍历找最后一个被传染的时间。时间往右依次加一,如果碰到了生气的人就归零。

C++
#include<bits/stdc++.h>
using namespace std;
int t,n,now,ans,is;
char a[105];
int main(){
	cin>>t;
	for(int x=1;x<=t;x++){
		cin>>n;
		ans=0,now=0,is=0;//初始化
		for(int i=1;i<=n;i++)cin>>a[i];
		for(int i=1;i<=n;i++){
			if(a[i]=='A')now=0,is=1;
			else if(is==1)now++;
        	ans=max(ans,now);//取最大值
		}
		cout<<ans<<endl;
	}
	return 0;
}
原文