题解 | 穷哈哈~

穷哈哈~

https://www.nowcoder.com/practice/5b3184b233f34fb39a7f259ae82eb42c

以后坚持每日一题以及题解.

day1:由题意模拟即可,找最长的"ahah...ah.."或者"haha...ha..",记录最长的长度

#include <iostream>
using namespace std;

int main() {
    int n;string s;cin>>n>>s;
    int ans = 0;
    for(int i=0;i<n;)
    {
        if(s[i]=='a'||s[i]=='h')
        {
            int j=i+1;
            for(;j<n;)
                if(s[j]!=s[j-1]&&(s[j]=='h'||s[j]=='a'))j++;
                else break;
            int cnt = j-i;
            ans = max(ans,cnt);
            i = j;
            continue;
        }
        i ++;
    }
    cout<<ans<<endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
05-09 15:06
求好运眷顾🙏🏻:翻译:面试前没盘点好hc一下面太多了,现在在排序回去等通知
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务