题解 | 穷哈哈~
穷哈哈~
https://www.nowcoder.com/practice/5b3184b233f34fb39a7f259ae82eb42c
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int count=0,ans=0,n;
cin>>n;
stack<char> s;
cin>>str;
for(int i=0;i<n;i++){
if(str[i]=='a'||str[i]=='h'){
if(s.empty()||s.top()!=str[i]){
s.push(str[i]);
count++;
}else{
count=1;
while(!s.empty()){
s.pop();
}//清空栈
s.push(str[i]);
}
}else{
count=0;
while(!s.empty()){
s.pop();
}//清空栈
}
ans=max(ans,count);
}
cout<<ans;
}
// 64 位输出请用 printf("%lld")
