시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 14 10 8 66.667%

문제

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.

서브태스크

번호 배점 조건
1 21

|s| ≤ 20

2 26

|s| ≤ 5000

3 53

|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)

채점 및 기타 정보

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