시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB113523638.298%

문제

Russian scientists are working on several promising topics. One of them is the quality of laugh. In this research they analyse the human speech and extract the laugh from it.

The scientists already made the software which converts speech to text. They consider a string of alternating letters “h” and “a” to be a laugh. For example, strings “ahahaha”, “hah” and “a” are laughs, but “abacaba” and “hh” are not.

You are given a string s containing the text. Find the length of the longest substring which is considered a laugh.

구현

You should implement the following function (method):

  • int longest_laugh(string s). This function should return the length of the longest substring of s which is considered a laugh.

Please use the provided template files for details of implementation in your programming language.

예제 1

  • s = “ahaha

The whole string is a laugh, so the answer is 5.

예제 2

  • s = “ahahrunawayahahsofasthah

The longest substring is “ahah”, so the answer is 4.

예제 3

  • s = “ahahaahaha

The longest substring is “ahaha”, so the answer is 5.

서브태스크

번호배점제한
121

|s| ≤ 20

226

|s| ≤ 5000

353

|s| ≤ 105

샘플 그레이더

The sample grader reads the input in the following format:

  • line 1: string s.

제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

채점 및 기타 정보

  • 예제는 채점하지 않는다.